怎么样把改成纵列(SQL语句怎么写)(50分)

  • 主题发起人 主题发起人 ProgramFan
  • 开始时间 开始时间
P

ProgramFan

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我写的SQL语句
SELECT COUNT(*) AS A
FROM dbo.EmployeeAttend
WHERE (LineName = 'A')
UNION ALL
SELECT COUNT(*) AS B
FROM dbo.EmployeeAttend
WHERE (LineName = 'B')
UNION ALL
SELECT COUNT(*) AS 'C'
FROM dbo.EmployeeAttend
WHERE (LineName = 'C')

得到的结果是这样的
A
-----------
26
27
0
(所影响的行数为 3 行)

但是我想要的结果是这样的
A  B  C
-----------
26  27  0

要怎样才能改成这样呢!
SQL语句应该怎样写呢?
 
SELECT sum(case when linename='a' then 1 else 0 end),
sum( case when
.......
FROM dbo.EmployeeAttend
 
另外的办法参考
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1261656
 
to:tseug:
这个我已经问了两次了,你都叫我去看那里,我看过了但是不行.

to:ugvanxk:
我用只要统计有多少条记录.用你的方法有一点问题.再帮我看一下好吗?
得到的结果都是一样的
 
这是我自己做的关于性别变成列的例子,你可以参考一下
select sum(sex1),sum(sex2) from (select sum(1) as sex1,0 as sex2 From jbb where sex='1'
union all
select 0 as sex1,sum(1) as sex2 From jbb where sex='2')
 
Select (SELECT COUNT(*) FROM dbo.EmployeeAttend
WHERE (LineName = 'A')) as A,
(SELECT COUNT(*) FROM dbo.EmployeeAttend
WHERE (LineName = 'B')) as B ,
(SELECT COUNT(*) FROM dbo.EmployeeAttend
WHERE (LineName = 'C')) as C

 
接受答案了.
 
后退
顶部