MySQL查询以计算植物的拾取数字数量
我正在尝试通过植物和皮卡登录年份获得独特的拾取数字
pickdate picknumber Plant
1/3/2022 L009803 Seattle
1/3/2022 L009803 Seattle
1/3/2022 L009803 Seattle
1/20/2022 L19033 Irving
1/21/2022 KL89231 Mini chih
1/23/2022 MY12341 kettle
1/23/2022 MY12341 kettle
1/25/2022 FD1211 Seattle
1/26/2022 HJ12W1 Irving
2/11/2022 K231245 Irving
2/11/2022 K231245 Irving
2/15/2022 N12ER1 Mini chih
2/21/2022 JS1234 Irving
2/25/2022 MK12E1 Kettle
我希望到达下面的桌子,以获取植物和TimePeriod的独特拾取数字,
Time period Seattle Irving Mini chih Kettle
Jan-22 2 2 1 1
Feb-22 0 2 1 1
请找到DDL的DDL输入表..
create table input
(pickdate date,
picknumber varchar(40),
plant varchar(20))
insert into input values
('1/3/2022','L009803','Seattle'),
('1/3/2022','L009803','Seattle'),
('1/3/2022','L009803','Seattle'),
('1/20/2022','L19033','Irving'),
('1/21/2022','KL89231','Mini chih'),
('1/23/2022','MY12341','kettle'),
('1/23/2022','MY12341','kettle'),
('1/25/2022','FD1211','Seattle'),
('1/26/2022','HJ12W1','Irving'),
('2/11/2022','K231245','Irving'),
('2/11/2022','K231245','Irving'),
('2/15/2022','N12ER1','Mini chih'),
('2/21/2022','JS1234','Irving'),
('2/25/2022','MK12E1','Kettle')
I am trying to get the distinct count of pickup numbers by plant and pickupmonth year
Input
pickdate picknumber Plant
1/3/2022 L009803 Seattle
1/3/2022 L009803 Seattle
1/3/2022 L009803 Seattle
1/20/2022 L19033 Irving
1/21/2022 KL89231 Mini chih
1/23/2022 MY12341 kettle
1/23/2022 MY12341 kettle
1/25/2022 FD1211 Seattle
1/26/2022 HJ12W1 Irving
2/11/2022 K231245 Irving
2/11/2022 K231245 Irving
2/15/2022 N12ER1 Mini chih
2/21/2022 JS1234 Irving
2/25/2022 MK12E1 Kettle
I am looking to get to the below table to get the distinct count of pickup numbers by plant and timeperiod
Time period Seattle Irving Mini chih Kettle
Jan-22 2 2 1 1
Feb-22 0 2 1 1
Please find the DDL for the input table..
create table input
(pickdate date,
picknumber varchar(40),
plant varchar(20))
insert into input values
('1/3/2022','L009803','Seattle'),
('1/3/2022','L009803','Seattle'),
('1/3/2022','L009803','Seattle'),
('1/20/2022','L19033','Irving'),
('1/21/2022','KL89231','Mini chih'),
('1/23/2022','MY12341','kettle'),
('1/23/2022','MY12341','kettle'),
('1/25/2022','FD1211','Seattle'),
('1/26/2022','HJ12W1','Irving'),
('2/11/2022','K231245','Irving'),
('2/11/2022','K231245','Irving'),
('2/15/2022','N12ER1','Mini chih'),
('2/21/2022','JS1234','Irving'),
('2/25/2022','MK12E1','Kettle')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有条件聚合:
或:
请参阅
With conditional aggregation:
Or:
See the demo.