• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to create a column that shows if a date appears in the last 7 days in BQ?

Resolved: How to create a column that shows if a date appears in the last 7 days in BQ?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’ve got a table that shows me a user_id and the dates they were active (this is derived from a massive events table). The table looks like this:
user_id active_date
1 2022-06-16
2 2022-06-02
1 2022-06-14
1 2022-05-01

I need to create a query to find if a user has been active in the last 7 days, 8-14 ago, 15-21 days ago, and 22-28 days ago, as well as their first and last active date. I’d like to see the active in the last 7 days column (and the others of that type) as a Boolean if possible.
The first and last active dates are pretty easy, but I need some help with the other dates. This is what I’ve got so far:

Answer:

An approach using DATE_DIFF:

If you have better answer, please add a comment about this, thank you!

google-bigquery sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Resolved: Can’t access static methods from outside until JavaScript’s static block is over?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.