Skip to content
Advertisement

Is there a way to have SQL SELECT a column with a different date?

I’m trying to pull a pretty simple report that reviews the last day’s data. It looks similar to this:

This works fine, but I’ve been asked to have a column present that shows day before count as well for comparison. I’m not really sure how to do this since the datetime condition is already specifying the last day. Is there a way to make this work so the select list would look like this for example?

Edit: Sample Data:

Desired Results:

Advertisement

Answer

This should work if you don’t have a time component. If you do, just change the “Y.[Date] =” to a BETWEEN as with the first part.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement