c_pattle Posted August 6, 2011 Share Posted August 6, 2011 I have a sql statement which is select * from invoices where username="gtd" order by invoice_date I want to edit it so to get the total of a field called "invoice_total" so the statement will now look like this select *, sum(invoice_total) from invoices where username="gtd" order by invoice_date However when I do this I now only get 1 record returned rather than before when I got 5 records returned. Is there are way to get around this problem? Thanks for any help Link to comment https://forums.phpfreaks.com/topic/244032-mysql-sum-problem/ Share on other sites More sharing options...
fenway Posted August 6, 2011 Share Posted August 6, 2011 Well, you're missing a GROUP BY column -- based on something like invoice_number, perhaps? But then * is useless. Link to comment https://forums.phpfreaks.com/topic/244032-mysql-sum-problem/#findComment-1253265 Share on other sites More sharing options...
c_pattle Posted August 7, 2011 Author Share Posted August 7, 2011 If I use group by then I don't get the overall total but just the total for each record. Would you recommend just having a seperate sql statement? Link to comment https://forums.phpfreaks.com/topic/244032-mysql-sum-problem/#findComment-1253710 Share on other sites More sharing options...
fenway Posted August 8, 2011 Share Posted August 8, 2011 You can use the "WITH ROLLUP" modifier to GROUP BY if you'd like. Link to comment https://forums.phpfreaks.com/topic/244032-mysql-sum-problem/#findComment-1254229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.