简体   繁体   中英

SQL Code for counts over different time periods

表

I need to figure out how to answer this: Find the number of property views per branch within 1 month, 2 months, and 3 months of client registration in one query.

I'm struggling with how to put this in one query, would CASE be the best way?

Thanks for any input.

You could probably just use UNION

select '1 month' as type, count(*) from tablename where month < 1
union
select '2 month' as type, count(*) from tablename where month < 2
union
select '3 month' as type, count(*) from tablename where month < 3

This would yield your counts as 3 different rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM