这是我的查询。
SELECT atdate,format(atdate,'ddd') as att_date,LvType FROM leavtran
WHERE AtDate between ('2019-02-01') and ('2019-02-28')
我想要在DateTime列中添加一个星期日。
答案 0 :(得分:0)
您希望在2月的所有时间 。基本上,这建议使用LEFT JOIN
。您没有提到数据库,但是想法是这样的:
SELECT dt.atdate, FORMAT(dt.atdate, 'ddd') as att_date, lt.LvType
FROM (SELECT '2019-02-01' as dte UNION ALL
SELECT '2019-02-02' as dte UNION ALL
. . .
SELECT '2019-02-28' as dte
) d LEFT JOIN
leavtran lt
ON lt.AtDate = d.dte ;
在特定情况下,您也可以仅将UNION ALL
与星期日日期一起使用:
SELECT lt.atdate, format(lt.atdate,'ddd') as att_date, lt.LvType
FROM leavtran
WHERE lt.AtDate BETWEEN '2019-02-01' AND '2019-02-28'
UNION ALL
SELECT '2019-02-03', 'Sun', NULL
UNION ALL
SELECT '2019-02-10', 'Sun', NULL
UNION ALL
SELECT '2019-02-17', 'Sun', NULL
UNION ALL
SELECT '2019-02-24', 'Sun', NULL
ORDER BY atdate;