SELECT *
FROM (select T.*,
ROW_NUMBER() OVER(PARTITION BY saasdm, ywdj order BY shrq) RN
FROM (select saasdm as saasdm, dbh as ywdj, shrq
from ZCCZ_SBSPJLB
WHERE shjg in ('1', '3') and saasdm = '493438229' and (dbh = '2011000016' or dbh = '2011000015')
GROUP BY saasdm, dbh, shrq
ORDER BY saasdm, dbh, shrq) T)
参考:https://blog.csdn.net/congweijing/article/details/86482916
https://blog.csdn.net/congweijing/article/details/86482916
本文深入探讨了使用SQL进行复杂查询的技术,特别是如何利用ROW_NUMBER()函数和子查询来实现数据的高效筛选与排序。通过具体案例,展示了如何在特定条件下获取所需的数据行,为数据库操作提供了实用的解决方案。
摘要由CSDN通过智能技术生成