News for hackers. Stuff that matters.
Re:Medium-hard SQL interview questions by PeterisP on Sunday May 03, 2020 @10:12AM (#23059090)
This seems fishy - if your data has a whole day gap somewhere for whatever reason (e.g. I'm thinking sales data where certain emergencies might result in an unusual, unplanned 'zero day') then that query silently gives a wrong result, IMHO a trailing week total should always include a specific date boundary calculation to ensure that it's really a week.
Re:Medium-hard SQL interview questions by WoahNoun on Sunday May 03, 2020 @01:08PM (#23060309)
For the transactional DB sure, an analytic DB / data warehouse / or even just table would have a 0 record for the no sales day. If there are gaps in daily data, at some point they need to be filled in with 0s. You can either do that at report building or query time using a cartesian join or you can fill the nulls with 0s during the data engineering pipeline. A robust BI process should do the later.

For example, if I want to plot this trailing calculation and it has gaps in the data, then the plot will be very wrong. The DE pipeline should fill in these gaps.

Re:Medium-hard SQL interview questions by artwr on Sunday May 03, 2020 @04:31PM (#23061638)
Two ways to address this: - Join to a date dimension and coalesce nulls to 0 - use RANGE BETWEEN (only available in some DBs) on a date_difference column