回复

kongcn 2010-01-15 08:45:13
我觉得和other字段没有关系,
查询语句用
select ID,NAME, other,max(VALUE) as value
from tb
group by ID,NAME
order by ID,NAME
就可以了。没必要那么麻烦。
...全文
69 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kongcn 2010-01-19
  • 打赏
  • 举报
回复
大家好。我是回复别人的帖子的时候不小心给发成问题了,谢谢大家的热情,我当时确实忘了写other。下次一定更加小心仔细!
yananguo_1985 2010-01-15
  • 打赏
  • 举报
回复

select ID,NAME, other,max(VALUE) as value
from tb
group by ID,NAME
order by ID,NAME

执行肯定不成功

1、在order后加other
2、在other上加聚集函数
中国风 2010-01-15
  • 打赏
  • 举报
回复
改為這樣

select * from TB  as a where not exists(select 1 from TB where ID=a.ID and Name=a.Name and Value>a.Value)
J1985Z 2010-01-15
  • 打赏
  • 举报
回复
不能保证id,name和other 是一对一的 group by 之后other 里的内容没法合并
--小F-- 2010-01-15
  • 打赏
  • 举报
回复
你不把other写里面试试?会报错的
要不你就在OTHER上加聚合函数
bancxc 2010-01-15
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!
andysun88 2010-01-15
  • 打赏
  • 举报
回复
会报错的,在select里面的有聚合函数的,一定都要放在group by 后面,
other 也不例外,这样即可

        select ID,NAME,max(VALUE) as value 
from #tb
group by ID,NAME
order by ID,NAME
ws_hgo 2010-01-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 beirut 的回复:]
[Quote=引用楼主   kongcn   的回复:]
我觉得和other字段没有关系,
查询语句用
select   ID,NAME,   other,max(VALUE)   as   value
from   tb
group   by   ID,NAME
order   by   ID,NAME
就可以了。没必要那么麻烦。
[/Quote]
这个可以执行吗?
[/Quote]

这个语句有问题
黄_瓜 2010-01-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 kongcn 的回复:]
我觉得和other字段没有关系,
查询语句用
select ID,NAME, other,max(VALUE) as value
from tb
group by ID,NAME
order by ID,NAME
就可以了。没必要那么麻烦。
[/Quote]
这个可以执行吗?
Mr_Nice 2010-01-15
  • 打赏
  • 举报
回复
select ID,NAME, other,max(VALUE) as value 
from tb
group by ID,NAME
order by ID,NAME


other 不包含在聚合里面不能顺利执行的哦!

联机丛书
如果 SELECT 子句 <select list> 中包含聚合函数,则 GROUP BY 将计算每组的汇总值。指定 GROUP BY 时,选择列表中任意非聚合表达式内的所有列都应包含在 GROUP BY 列表中,或者 GROUP BY 表达式必须与选择列表表达式完全匹配。


SQL77 2010-01-15
  • 打赏
  • 举报
回复
select ID,NAME, other,max(VALUE) as value
from tb
group by ID,NAME
order by ID,NAME

肯定有关系,你是按他来分组


select ID,NAME, other,[VALUE] as [value]
from tb T WHERE [VALUE]=(SELECT MAX([VALUE]) FROM TB WHERE
ID=T.ID AND NAME=T.NAME)
Rockets_NBA 2010-01-15
  • 打赏
  • 举报
回复
?

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧