'Google BigQuery select max for each day
I have a problem with my BigQuery select, I need to get the max value for the column (students) for each day.
SELECT EXTRACT(DATE FROM timestamp) as date, ARRAY_LENGTH(student_ids) as students from analytics.daily_active_students_count order by timestamp desc
| Row | Date | Students |
|---|---|---|
| 1 | 2022-05-16 | 72 |
| 2 | 2022-05-16 | 33 |
| 3 | 2022-05-16 | 12 |
| 4 | 2022-05-15 | 10 |
| 5 | 2022-05-15 | 84 |
| 6 | 2022-05-15 | 8 |
| 7 | 2022-05-14 | 92 |
| 8 | 2022-05-14 | 105 |
| 9 | 2022-05-14 | 12 |
Query should remove duplicated rows for days and take only rows with max number of students.
I want my output looks like this:
| Row | Date | Students |
|---|---|---|
| 1 | 2022-05-16 | 72 |
| 2 | 2022-05-15 | 84 |
| 3 | 2022-05-14 | 105 |
Solution 1:[1]
Problem was that my backend used different timezone. I solved this issue with casting timestamp:
DATE(DATETIME(TIMESTAMP, "Europe/Zagreb")) as date
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jurica Ĺ ogori? |
