select c_a from tb_a where c_b=(select max(c_b) from tb_a) select a.c_a from tb_a a where not exists(select 1 from tb_a where c_b>a.c_b)两个语句都可以,相对而言,好像第一个更好理解
create table [tb_a] ( [c_a] [int] null, [c_b] [int] null ) go insert into tb_a select 1,3 union select 4,2 union select 8,4 union select 7,7 union select 3,9 select * from tb_a select c_a from tb_a where c_b=(select max(c_b) from tb_a) select a.c_a from tb_a a where not exists(select 1 from tb_a where c_b>a.c_b)
--测试数据 create table [tb_a] ([c_a] [int] null,[c_b] [int] null) go insert into tb_a select 1,3 union select 1,2 union select 2,4 union select 2,7 union select 3,9 --查询 select top 1 c_a, sum(c_b) from tb_a group by c_a order by sum(c_b) desc --清除 drop table tb_a
select c_a from (select top 1 c_a, sum(c_b) c_b from tb_a group by c_a order by sum(c_b) desc) a
select c_a from tb_a where c_b=(select max(c_b) from tb_a)
描述不清,重描一次某表tb_a,列c_a,c_b 首先按c_a分组,将c_b求和 求按c_a分组,将c_b求和后 sum(c_b)的值为最大的那条记录的c_a的值 请写出具体语句 _____________________________________________________________select top 1 c_a from tb_a group by c_a order by sum(c_b) desc
--试试 Select top 1 * (Select C_a,sum(C_b) C_b from tb_a group by C_a)a order by C_b desc
select c_a from (select top 1 c_a, sum(c_b) c_b from tb_a group by c_a order by sum(c_b) desc) a这样还不行么?
还要把这个值赋给一个参数@H, ________________________________declare @H 数据类型 set @H=(select top 1 c_a from tb_a group by c_a order by sum(c_b) desc)
from tb_a
where c_b=(select max(c_b) from tb_a)
首先按c_a分组,将c_b求和
求按c_a分组,将c_b求和后
sum(c_b)的值为最大的那条记录的c_a的值
请写出具体语句
select a.c_a from tb_a a where not exists(select 1 from tb_a where c_b>a.c_b)两个语句都可以,相对而言,好像第一个更好理解
[c_a] [int] null,
[c_b] [int] null
)
go
insert into tb_a
select 1,3 union
select 4,2 union
select 8,4 union
select 7,7 union
select 3,9
select * from tb_a
select c_a from tb_a where c_b=(select max(c_b) from tb_a)
select a.c_a from tb_a a where not exists(select 1 from tb_a where c_b>a.c_b)
create table [tb_a] ([c_a] [int] null,[c_b] [int] null)
go
insert into tb_a
select 1,3 union
select 1,2 union
select 2,4 union
select 2,7 union
select 3,9
--查询
select top 1 c_a, sum(c_b)
from tb_a
group by c_a
order by sum(c_b) desc
--清除
drop table tb_a
from tb_a
group by c_a
order by sum(c_b) desc) a
首先按c_a分组,将c_b求和
求按c_a分组,将c_b求和后
sum(c_b)的值为最大的那条记录的c_a的值
请写出具体语句
_____________________________________________________________select top 1 c_a from tb_a group by c_a order by sum(c_b) desc
Select top 1 * (Select C_a,sum(C_b) C_b from tb_a
group by C_a)a
order by C_b desc
from tb_a
group by c_a
order by sum(c_b) desc) a这样还不行么?
________________________________declare @H 数据类型
set @H=(select top 1 c_a from tb_a group by c_a order by sum(c_b) desc)