Jump to content

Bizar result using SUM


cpd

Recommended Posts

I've got a list of sundries in a relational database and there are currently 2 for this particular booking. When using the SUM function it only returns a single sundry where as without the SUM it returns both rows.

 

SELECT s.sundryID, s.name, s.cost, bs.quantity, (bs.quantity * s.cost) AS sundry_total, r.roomNo, SUM(bs.quantity * s.cost) AS total FROM bookings_sundries AS bs
LEFT JOIN sundries AS s ON s.sundryID = bs.sundryID
LEFT JOIN bookings_details AS bd ON bd.id = bs.bookingDetailsID
LEFT JOIN rooms AS r ON r.roomID = bd.roomID
WHERE b.bookingID = 1

 

I'm baffled as to why. The total column appears no problem but like I said it only shows a single row as opposed to both the rows. I would have expected both rows to be shown with the `total` appearing at the end of each row.

 

Bare in mind this is all happening in phpMyAdmin.

Link to comment
https://forums.phpfreaks.com/topic/263388-bizar-result-using-sum/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.