Created
May 12, 2022 14:08
-
-
Save jingyang-li/acf33035af0dc13ee3ecfbcff5f4c385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table datatable (TrendType varchar(12), date date, sales int) | |
insert into datatable values ('Monthly','5/1/2021',1234), | |
('Monthly','3/1/2021',1234), | |
('Monthly','2/1/2022',1234), | |
('Monthly','5/1/2022',1234), | |
('Monthly','8/1/2021',1234), | |
('Monthly','8/1/2022',1234), | |
('Monthly','12/1/2021',1234), | |
('Monthly','11/1/2022',1234) | |
select 'Quarterly' TrendType, DATEADD(Q, DATEDIFF(Q, 0, [date]) , 0) as [date], | |
Sum(sales) Sales from datatable | |
group by DATEADD(Q, DATEDIFF(Q, 0, [date]) , 0) | |
order by DATEADD(Q, DATEDIFF(Q, 0, [date]) , 0) | |
drop table datatable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment