SELECT TOP 10 nd,wh,se,te,sc,ld,de FROM Ar a WHERE (te='产经纵横') AND (ts=1) AND (se=1) AND not exists(SELECT 1 FROM Ar WHERE te=a.te and nd<a.nd group by te) ORDER BY  de DESC这是我的筛选,为什么筛选后所有相同记录都没了.我想只保留一条te相同的记录.该怎么做?

解决方案 »

  1.   

    SELECT TOP 10 nd,wh,se,te,sc,ld,de FROM Ar a WHERE (te='产经纵横') AND (ts=1) AND (se=1) AND not exists(SELECT 1 FROM Ar WHERE te=a.te and nd<a.nd) ORDER BY  de DESC
      

  2.   

    SELECT TOP 10 nd,wh,se,te,sc,ld,de FROM Ar a WHERE (te='产经纵横') AND (ts=1) AND (se=1) AND not exists(SELECT 1 FROM Ar WHERE te=a.te AND (ts=1) AND (se=1) and nd<a.nd) ORDER BY  de DESC
      

  3.   

    SELECT TOP 10 nd,wh,se,te,sc,ld,de FROM Ar a WHERE (te='产经纵横') AND (ts=1) AND (se=1) AN nd in (SELECT nd FROM Ar WHERE te=a.te and nd<a.nd) ORDER BY  de DESC
      

  4.   

    你最好在表中有一个唯一标识列,要用二楼的,就必须保证列nd是唯一列,要不然,就用表中的唯列来取代查询表达式中的nd
      

  5.   

    你的表达式中
    SELECT 1 FROM Ar WHERE te=a.te and nd<a.nd group by te
    只要nd列在te相等的情况下有不同值,查出的结果是该te值所在的行为真,再加上前面的not exists否定,这些行就不会返回了
      

  6.   

    SELECT TOP 10 nd,wh,se,te,sc,ld,de FROM Ar a WHERE (te='产经纵横') AND (ts=1) AND (se=1) AND not exists(SELECT 1 FROM Ar WHERE te=a.te and nd>a.nd) ORDER BY  de DESC大哥试一下看行不
      

  7.   

    nd列在te相等的情况下有不同值时,一样不会返回的.你可以自己分析一下
    not exists(SELECT 1 FROM Ar WHERE te=a.te and nd>a.nd)