我有一个表
col1 col2
1 12
1 14
1 234
2 53
2 42
3 15
3 73
3 32
3 6
想做一个查询,将相同的col1里在col2中最大的数字挑出来,结果为:
col1 col2
1 234
2 53
3 73
谢谢各位高人
然后我想添加一列,将这个最大的数字标志为1,谢谢各位!
col1 col2
1 12
1 14
1 234
2 53
2 42
3 15
3 73
3 32
3 6
想做一个查询,将相同的col1里在col2中最大的数字挑出来,结果为:
col1 col2
1 234
2 53
3 73
谢谢各位高人
然后我想添加一列,将这个最大的数字标志为1,谢谢各位!
set col3 = 1
from ta
where exists(select 1 from (
select col1,max(col2) col2 from tagroup by col1) b
where b.col1 = col1 and b.col2 = col2
)
col1 col2
1 12
1 14
1 234
2 53
2 42
3 15
3 73
3 32
3 6
想做一个查询,将相同的col1里在col2中最大的数字挑出来,结果为:
col1 col2
1 234
2 53
3 73
谢谢各位高人
然后我想添加一列,将这个最大的数字标志为1,谢谢各位!select col1 , max(col2) col2 from tb group by col1
select t1.*,maxflag=
(case
when col2 = (select max(t2.col2) from tb t2 where t2.col1=t1.col1)
then 1
else 0
end) from tb t1如果同一个col1中有两个相同的col2最大值,则都标为1.