有没有一种方法可以填充一个结果中省略的行 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来实现这一点?
hlswsv351#
一种解决方案是一个帮助表,其中有一个整数列,其值从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);
1条答案
按热度按时间hlswsv351#
一种解决方案是一个帮助表,其中有一个整数列,其值从1到最大值(31?)。