add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE mytable
([date] date, [state] varchar(8), [storeid] int, [item] varchar(1), [units] int)
;
INSERT INTO mytable
([date], [state], [storeid], [item], [units])
VALUES
('2020-01-22 ', 'new york', 712, 'a', 5),
('2020-01-22 ', 'new york', 712, 'b', 7),
('2020-02-18 ', 'new york', 712, 'c', 0),
('2020-05-11 ', 'new york', 518, 'b', 9),
('2020-01-22 ', 'new york', 518, 'b', 10),
('2020-01-21 ', 'oregon', 613, 'b', 0),
('2020-02-13 ', 'oregon', 613, 'b', 9),
('2020-04-30 ', 'oregon', 613, 'b', 10),
('2020-01-22 ', 'oregon', 515, 'c', 3)
;
9 rows affected
select state, count(*) q1total
from (
select distinct state, storeid, item
from mytable
where date between '2020-01-01' and '2020-03-31' and units > 0
) t
group by state
state q1total
new york 3
oregon 2