Sqlserver 根据某个字段分组查询

  SELECT top 1000000   C.ISBN as ISBN,M.DLH as OuterKey,C.TITLE as 图书标题,C.CBZ as 出版社,C.DYZRZ as 作者,C.YJCS as 总页数,C.CNY as 价格,C.KB as 尺寸,C.ZTC as 备注,C.FLH as 分类号,C.SSH as 索书号,C.PJH as 种次号,状态=2,媒体类型=1
  FROM [libv60].[dbo].[TSG_TSGC] C join [libv60].[dbo].[TSG_TXM] M on C.SJHRK=M.SJHRK where M.DLH is not null and M.DLH>100000 and C.TITLE not in(select C.TITLE  from TSG_TSGC where TITLE=C.TITLE and DLH>M.DLH)

加粗部分是重点。

你可能感兴趣的:(Sqlserver 根据某个字段分组查询)