SQl Server 查询 问题
有一个表有三个字段A,B,C,插入三行数据 第一行1,2,3 第二行2,4,6第三行3,5,4
查询出这个表中各个数字的个数。
求大神
[解决办法]
with tb(A,B,C) as
(
select 1,2,3 union all
select 2,4,6 union all
select 3,5,4
)
, tb2 (result) as
(
select A from tb
union all
select B from tb
union all
select C from tb
)
select result, COUNT(result)
from tb2
group by result
[解决办法]
你还没下班吗。
这样吗:
create table tb(a int, b int,c int)
insert into tb
select 1,2,3 union all
select 2,4,6 union all
select 3,5,4
go
select x,COUNT(*) as '次数'
from
(
select a x from tb union all
select b from tb union all
select c from tb
)t
group by x
/*
x次数
11
22
32
42
51
61
*/