【发布时间】:2019-03-11 07:30:23
【问题描述】:
有一个“事件”表,其中包含如下所示的数据:
no | qty | events
----------------------
001 | 10 | Printed
004 | 10 | Printed
007 | 10 | Printed
004 | 2 | Reprint
并且有一个“数字”表,其中包含如下所示的数据:
start_no | no | serial | expiry_date
--------------------------------------------
001 | 001 | 9311 | 2019-03-03
001 | 002 | 9312 | 2019-03-03
001 | 003 | 9313 | 2019-03-03
004 | 004 | 9314 | 2019-03-06
004 | 005 | 9315 | 2019-03-06
004 | 006 | 9316 | 2019-03-06
007 | 007 | 9317 | 2019-03-10
007 | 008 | 9318 | 2019-03-10
这是我使用的查询:
SELECT start_no, n.no, n.serial, expiry_date, qty
FROM Numbers n
INNER JOIN Events e ON n.start_no = e.no
WHERE events='Printed'
我需要查询会返回如下结果:
start_no | no | serial | expiry_date
--------------------------------------------
001 | 003 | 9313 | 2019-03-03
004 | 006 | 9316 | 2019-03-06
007 | 008 | 9318 | 2019-03-10
我该怎么做?
【问题讨论】:
标签: sql sql-server select group-by