mpower Posted December 7, 2006 Share Posted December 7, 2006 Hi,I'm not that used to MySQL, yet. I wonder if it's possible to do the following grouping with summery on a record set?Tha records set looks as follows:- type- topic- description- timeExample of data:Admin Email Email to customer A 0,25Admin Email Email to customer B 0,25Dev DB Customer A DB 1,25Dev DB Customer B DB 0,75Dev DB Customer A DB 0,50Admin Email Email to customer B 0,25I've done the following:[code]SELECT type, topic, descriptionFROM stampsGROUP BY type, topic[/code]This gives me:Admin Email Email to customer A 0,25Admin Email Email to customer B 0,25Dev DB Customer A DB 1,25Dev DB Customer B DB 0,75How I want it to look like is as follows:Admin Email Email to customer A 0,25Admin Email Email to customer B 0,50 Email to customer BDev DB Customer A DB 1,75 Customer A DBDev DB Customer B DB 0,75Is this possible in any way? Would be very pleased for a bit of help.Thanks in advance // Jonas Quote Link to comment Share on other sites More sharing options...
Vikas Jayna Posted December 7, 2006 Share Posted December 7, 2006 Check out this link http://dev.mysql.com/doc/refman/5.0/en/group-by-modifiers.html Quote Link to comment Share on other sites More sharing options...
mpower Posted December 7, 2006 Author Share Posted December 7, 2006 No, I don't think that solves my problem. Tried it a bit and it didn't do what I wanted it to.Please take a look at my description of the problem again. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 7, 2006 Share Posted December 7, 2006 [quote author=mpower link=topic=117722.msg480481#msg480481 date=1165500033]No, I don't think that solves my problem. Tried it a bit and it didn't do what I wanted it to.Please take a look at my description of the problem again.[/quote]I've reread the initial post several times, and I'm still not clear on what you want. Groupings are only able to be done with MySQL when you have some sort of aggregate functions going on (COUNT, SUM, AVG, etc). Otherwise, you need to handle it in PHP. You also mention summary listings, but I'm not following what your example output is trying to convey. Could you try to break it down and describe what your fields are and [b]how[/b] you want them summarized? Quote Link to comment Share on other sites More sharing options...
mpower Posted December 7, 2006 Author Share Posted December 7, 2006 When I've grouped by two, type and topic, I want the data for description to be shown for the second, thierd etc. row witch is in the group as well. I don't know if this is possible? In this case the descripton often isn't the same in each rows, as the type and topic. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 9, 2006 Share Posted December 9, 2006 When you aggregate, you lose all the rows you used to aggregate -- you'll have to do some fancy subqueries or joins to get both pieces. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.