MSSQL查询语句怎么写

MSSQL查询语句怎么写,第1张

select field1,field2 from table1 left join table2

on field1=field2(基准字段,可以多个)

where table1.field3=table2.field3

你好,很高兴回答你的问题,你可以试着用连接查询,希望能到你,where条件就用两个表的ID相等即可。希望能帮到你,望采纳。

创建表:

create table test

(b varchar(1),

c varchar(1))

insert into test values ('a','a')

insert into test values ('a','b')

insert into test values ('d','a')

insert into test values ('c','b')

insert into test values ('e','a')

insert into test values ('d','a')

insert into test values ('c','b')

insert into test values ('f','a')

insert into test values ('e','a')

执行:

select b,

sum(case when c='a' then 1 else 0 end) gs,

sum(case when c='b' then 1 else 0 end) gx

from test

group by b

结果:

最后一行你统计错了吧


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/69351.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-01
下一篇2023-03-01

发表评论

登录后才能评论

评论列表(0条)

    保存