开发者

sql: including data from multiple columns

开发者 https://www.devze.com 2022-12-29 19:47 出处:网络
i have a table that looks li开发者_开发百科ke this: alt text http://img405.imageshack.us/img405/3929/33732138.png

i have a table that looks li开发者_开发百科ke this:

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

another words i would like to take data from columns stuff1, stuff2, and stuff3, and put them together


The UNION command should suffice for what you want to do:

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消