grissom Posted March 3, 2011 Share Posted March 3, 2011 Hi, I am looking to output a MYSQL table in a certain way. Here's an example, imagine I have a sales database like this Staff Day Place Sales ==== === ==== ===== Alice MON Town 5 Alice MON City 6 Alice TUE Town 7 Bob TUE Town 3 Bob TUE City 2 And I'd like to turn it into something like this : Total Sales by Day MON TUE Alice 11 7 Bob 0 5 For sure I can do it in PHP using a few "loops" but is there a way to do it in a single MYSQL statement ? Link to comment https://forums.phpfreaks.com/topic/229485-outputting-a-table/ Share on other sites More sharing options...
grissom Posted March 3, 2011 Author Share Posted March 3, 2011 No matter, solved it ! select staff, sum(if(day ='MON', sales,0)), sum(if(day ='TUE', sales,0)), sum(if(day ='WED', sales,0)) from aliceandbob group by staff Link to comment https://forums.phpfreaks.com/topic/229485-outputting-a-table/#findComment-1182343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.