已关闭,此问题需要更focused。目前不接受答复。
**想改善这个问题吗?**更新问题,使其仅通过editing this post关注一个问题。
5小时前关闭
Improve this question
我需要为mySQL 8.0和Oracle 21c重写此SQL Server 2019查询
WITH yourTable AS (
SELECT 1 AS Item, '2021-05-01' AS Date, 200 AS Price UNION ALL
SELECT 1, '2021-06-11', 210 UNION ALL
SELECT 1, '2021-06-27', 225 UNION ALL
SELECT 1, '2021-08-01', 250 UNION ALL
SELECT 2, '2021-02-10', 600 UNION ALL
SELECT 2, '2021-04-21', 650 UNION ALL
SELECT 2, '2021-06-17', 675 UNION ALL
SELECT 2, '2021-07-23', 700
),
WITH cte AS (
SELECT *, DATEADD(day, -1, LEAD(Date, 1, GETDATE())
OVER (PARTITION BY Item
ORDER BY Date)) AS LastDate
FROM yourTable
) SELECT Item, Date AS DateStart, Price, LastDate AS DateEnd
FROM cte
ORDER BY Item, Date;
from question
我尝试使用GET_DATE,CURDATE,但它不工作
1条答案
按热度按时间13z8s7eq1#
对于mysql 8和Oracle 21c,使用
INTERVAL
代替DATEADD
,使用CURRENT_DATE
代替GETDATE()
:Demo here