I want to run following query into Bigquery
SELECT table1.field1, COUNT(table1.fiels2)
FROM table1
GROUP BY table1.fiels1
ORDER BY COUNT(table1.fiels2)
DESC limit 10;
I am getting error Error: (L1:282): expression COUNT([metamx_magnetic_share.adops001.cookie], DESC) in ORDER BY is invalid
But same query I am successfully ran on Vertica.
Any kind of help/suggestion would be appreciated.
Thanks
The use of the COUNT function in Bigquery is to return a single value from the number of rows in the input. The DISTINCT clause with COUNT is used only to eliminate any duplicate row in the table.
OFFSET means that the numbering starts at zero, ORDINAL means that the numbering starts at one. A given array can be interpreted as either 0-based or 1-based. When accessing an array element, you must preface the array position with OFFSET or ORDINAL , respectively; there is no default behavior.
Results from your query can be sorted by using the order_by argument. The argument can be used to sort nested objects too. The sort order (ascending vs. descending) is set by specifying the asc or desc enum value for the column name in the order_by input object, e.g. {name: desc} .
You can sort by an alias, but not a function, so try:
SELECT table1.field1, COUNT(table1.fiels2) as cnt
FROM table1
GROUP BY table1.fiels1
ORDER BY cnt
DESC limit 10;
The documentation is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With