34,593
社区成员
发帖
与我相关
我的任务
分享
---测试数据---
if object_id('[tb_A]') is not null drop table [tb_A]
go
create table [tb_A]([col1] varchar(2),[col2] int)
insert [tb_A]
select 'a',100 union all
select 'aa',300
---查询---
select
max(case col1 when 'a' then col2 end) as a,
max(case col1 when 'aa' then col2 end) as aa
from tb_A
---结果---
a aa
----------- -----------
100 300
create table tb_A(col1 varchar(10),col2 int)
insert into tb_A select 'a',100 union all select 'aa',300
select top 1 (select col2 from tb_A where col1='a') as a,(select col2 from tb_A where col1='aa') as aa from tb_A
drop table tb_A
select
max(case col1 when 'a' then col2 end) as a,
max(case col1 when 'aa' then col2 end) as aa
from tb_A