日期:2014-05-17  浏览次数:20691 次

为甚麽sql下面呢语句有错饿
SQL code

   SELECT * FROM T_ARTICLE  WHERE (N_ARTICLEID
   in  ( SELECT  DISTINCT C_TITLE, N_ARTICLEID  FROM T_ARTICLE  GROUP BY C_TITLE,N_ARTICLEID) )
   ORDER BY N_ARTICLEID DESC    





------解决方案--------------------
SELECT * FROM T_ARTICLE WHERE (N_ARTICLEID
in ( SELECT DISTINCT N_ARTICLEID FROM T_ARTICLE GROUP BY N_ARTICLEID) )
ORDER BY N_ARTICLEID DESC
in,前后的字段要对应,前面是N_ARTICLEID ,后面选择出来的必须也是N_ARTICLEID

------解决方案--------------------
select中的字段不可以单独出现,必须出现在group语句中或者在组函数中。
要不然把C_TITLE去掉,要不就把它放在GROUP BY 后面
------解决方案--------------------
SELECT * FROM T_ARTICLE WHERE ( (c_TITLE,N_ARTICLEID)
in ( SELECT DISTINCT C_TITLE, N_ARTICLEID FROM T_ARTICLE GROUP BY C_TITLE,N_ARTICLEID) )
ORDER BY N_ARTICLEID DESC
这样试下 你子查询是出来的是分组排序后不重复的两个字段的值 而你拿一个字段的值去跟两个字段的值比较肯定会出错 ,