主表:

SQL一对多特殊查询,取唯一一条

辅表:

SQL一对多特殊查询,取唯一一条

一个app对应多个apk,现在要取上线(Apk_Status最大的)的应用

select * from [dbo].[tbl_APP] as app 
join 

(select * from [dbo].[tbl_Apk] as AA where not exists(select top 1 * from tbl_Apk as BB where AA.Apk_APPId=BB.Apk_APPId and AA.Apk_Status < BB.Apk_Status))

 as apk on app.APP_Id = apk.Apk_APPId

重点是取关联的右表:

select * from [dbo].[tbl_Apk] as AA where not exists(select top 1 * from tbl_Apk as BB where AA.Apk_APPId=BB.Apk_APPId and AA.Apk_Status < BB.Apk_Status)

没看懂这个not exists的逻辑 ~~

相关文章:

  • 2021-09-24
  • 2022-02-07
  • 2022-02-02
  • 2021-12-16
  • 2021-04-15
  • 2022-12-23
  • 2021-09-09
猜你喜欢
  • 2022-12-23
  • 2022-02-20
  • 2021-10-18
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案