sql:包括来自多个列的数据

时间:2010-05-12 02:47:40

标签: sql ms-access

我有一张看起来像这样的表:

alt text http://img405.imageshack.us/img405/3929/33732138.png

另外一句话我想从列stuff1,stuff2和stuff3中获取数据,并将它们放在一起

2 个答案:

答案 0 :(得分:2)

UNION命令应该足以满足你的目标:

SELECT practice, stuff1 FROM table
UNION ALL
SELECT practice, stuff2 FROM table
UNION ALL
SELECT practice, stuff3 FROM table
ORDER BY practice

答案 1 :(得分:1)

select 
   practice, stuff1 as stuff, count(*)
from table
group by practice, stuff1
union
select 
   practice, stuff2 as stuff, count(*)
from table
group by practice, stuff2
union
select 
   practice, stuff3 as stuff, count(*)
from table
group by practice, stuff3