Earlier quoted context omitted.
This looks nearly the same, but it's much easier to write and generates less spurious diffs: select a , b , count(*) as count from table join table2 on table.key1 = table2.key1 and table.key2 = table2.key2 and DATEADD('day, 1, table.key3) = table2.key3 where cond1 and cond2 group by a, b order by count desc The largest difference is that the equal operators aren't aligned anymore, but on my opinion, aligning them is…
Nice changes, I like it! I will say I really like aligning the join clauses, but I'll try writing things this way for a little while and see if it sticks.
SELECT
a,
b,
count(*) as count
FROM
table
JOIN
table2
ON
table.key1 = table2.key1
AND
table.key2 = table2.key2
AND
-- 1 day apart
DATEADD('day', 1, table.key3) = table2.key3
WHERE
cond1
AND
cond2
AND
(
cond3
OR
cond4
)
GROUP BY
(a, b)
ORDER BY
count desc,
a asc
LIMIT
1000
;
Yes, that's a lot of whitespace, but it helps for complex queries.