MariaDB/Mysql SELECT from - to with Subquery



我有一个表'Device',其中包含安装日期和客户:

已安装tbody> <<tr>24
Id 设备名称客户
12021-10-101
B2021-10-101
32021-10-202
2021-10-303

Test this:

SELECT t1.DeviceName,
t1.Installed InstalledFrom,
t2.Installed InstalledTo,
t1.Customer
FROM Device t1
LEFT JOIN Device t2 ON t1.DeviceName = t2.DeviceName
AND t1.Installed < t2.Installed
WHERE NOT EXISTS ( SELECT NULL
FROM Device t3
WHERE t1.DeviceName = t3.DeviceName
AND t1.Installed < t3.Installed
AND t3.Installed < t2.Installed )

相关内容

  • 没有找到相关文章

最新更新