I am a beginner in SQL.
I'm sorry for the rudimentary question, but I'd appreciate it if you could let me know.
I'd like to count only people with number 90 or less by month.
Could you tell me the syntax?
create table mytable(
datetimesend date,
id char(1),
number integer
);
insert into mytable (datetimesend, id, number) values
('2018-08-23', 'a', 34),
('2018-08-23', 'b', 23),
('2018-08-23', 'c', 95),
('2018-08-23', 'd', 78),
('2018-09-30', 'e', 50),
('2018-09-30', 'f', 6),
('2018-09-30', 'g', 99')
;
I think you can simply specify it with the where
clause, but what do you think?
select sum(number) as sum, year(datetimesend) as year, month(datetimesend) as month
from mytable where number <=90 group by year, month;
© 2024 OneMinuteCode. All rights reserved.