Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

Mysql again, group by and display rest of rows

I have table:

id, day, user, value, active

And now i get SELECT day from ppl GROUP BY user

but! i want to get all days in one row, not only one

for example

day: 1,2,3,4,5,6,7,8,9... user: myusername

is it possible?

Yep,

SELECT
     user,
     GROUP_CONCAT(day) day
 FROM ppl
 GROUP BY 1;

Is answer for my question, but i've got next, last

Here is result of query http://screenshooter.net/0562655/24_05_2012__22_37_09

how to change

row 3 from 8,9,10 to 8-10
row 5 from 21,22,23,24,28,29,30 to 21-24,28-30
row 6 from 17,21,22,23,24,25 to 17,21-25

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
 SELECT
     user,
     GROUP_CONCAT(day) day
 FROM ppl
 GROUP BY 1;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...