-2

I am facing 1 issue with MySql query:

select sum(h.total_rooms) as total_rooms from reservation_details as rd LEFT JOIN hotels as h ON rd.hotel_id = h.id left join `chains` as `c` on `c`.`id` = `h`.`chain_id` where YEAR(rd.created_at) = 2016 and MONTH(rd.created_at) = 5 and rd.status >= 50 and h.chain_id = 2 GROUP BY rd.hotel_id

Above query returns :

total_rooms
48216
7700
13250

But I need sum of the query.

Rakesh Tripathi
  • 43
  • 1
  • 12

1 Answers1

0

Try to use sum() function like this and use ROLLUP with your query.

select sum(h.total_rooms) as total_rooms from reservation_details as rd 
LEFT JOIN hotels as h ON rd.hotel_id = h.id 
left join `chains` as `c` on `c`.`id` = `h`.`chain_id` 
where YEAR(rd.created_at) = 2016 and MONTH(rd.created_at) = 5 
and rd.status >= 50 and h.chain_id = 2 GROUP BY rd.hotel_id 
WITH ROLLUP
Satish Saini
  • 2,880
  • 3
  • 24
  • 38