0

New to DB. Here's the scenario

Table x

id(serial)    Col1(date/ts)     Col2(numeric)   Col3(numeric)    Col4-Generated(numeric) 
auto          Date of record    val1            val2             Preset formula using val1 & val2 

how do I do

select date_trunc('month',sum(Col1)), sum(Col2), sum(Col3), Col4 Preset formula ....

without using any aggregate function for Col4 or writing the actual formula?

  • 1
    `date_trunc('month',sum(Col1))` makes no sense. You can't "sum" a date - what is the sum of yesterday, today and the day after tomorrow? –  Jul 31 '20 at 08:29
  • Are you looking for something like this? https://stackoverflow.com/questions/62260703 –  Jul 31 '20 at 08:30
  • Sorry a mistake. I meant date_trunc('month', Col1) . On the second link you provided, its promising but in my example Col4 is a generated column (stored) with some formula on Col2 and Col3 so has values. – Purbarag Jena Jul 31 '20 at 09:28
  • @PurbaragJena . . . The SQL query does not know what formula is used to generate `col4`. It only knows what the values are. You have to provide some expression to get the aggregation you want. – Gordon Linoff Jul 31 '20 at 10:57

0 Answers0