Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法填写select语句结果中省略的行?
select
我有这样的数据:
person,day 1,20 1,24
...由这样的简单查询返回:
select * from example_table where day>=20
我想要的是为缺少的日子添加行,因此结果如下所示:
person,day 1,20 1,21 1,22 1,23 1,24
有没有办法通过 SQL 做到这一点?
一种解决方案是一个帮助表,其中包含一个整数列,其值从 1 到最大值(31?)。
select person, day from yourtable UNION ALL select intcol, from helptable h where not exists (select day from yourtable y where y.day = h.helptable);