在sqlserver2005中无法验证这句话:包含 GROUP BY 的子查询不能使用 DISTINCT 关键字。
请各位大侠帮忙验证!
以下代码在sqlserver2005中可以执行:
select distinct teamname from score
where teamName in
(select distinct teamName from score group by teamname)
group by teamname
请各位大侠帮忙验证!
以下代码在sqlserver2005中可以执行:
select distinct teamname from score
where teamName in
(select distinct teamName from score group by teamname)
group by teamname
distinct是去重,group by 是分组。
select
*
from
tb t
where
id=(select max(id) from tb where teamName=t.teamName)
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/17988c0f-0df4-4063-a0b3-82b21d22fb2b正如你说的,这个规则应该是错误的。
使用的环境不同,一般在统计的时候就用到GROUP BY
而另一个就是去重复的.
如果说在筛选的情况下,两者可以通用!
where teamName in
(select distinct teamName from score group by teamname)
group by teamname ======================
select distinct teamname from score
where teamName in
(select distinct teamName from score group by teamname)