简体   繁体   中英

google bigquery SQL group by aggregate function

In big-query standard SQL I get the error message:

"Error: Column 7 contains an aggregation function, which is not allowed in GROUP BY at [17:22]

where column 7 is defined in the select clause as follows:-

CASE WHEN MIN(transaction_dttm) = transaction_dttm THEN 'NEW' ELSE 'EXISTING' END AS Fcquisition_Flag

Please note that transaction_date is a timestamp.

Any suggested solutions appreciated.

Perhaps you just want window function in a subquery:

SELECT . . .
FROM (SELECT . . . ,
             (CASE WHEN transaction_dttm = MIN(transaction_dttm) OVER (PARTITION BY ?)
                   THEN 'NEW' ELSE 'EXISTING'
              END) AS Fcquisition_Flag
      FROM . . . 
     ) t
GROUP BY 1, 2, 3, 4, 5, 6, 7

It is unclear what you want in the PARTITION BY .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM