hello friends i have 2 tables like below
tab_a --> "unit_info_id" ,"unit_id" ,"p_id" ,"p_bathroom" ,"p_bedroom" ,"p_size" ,"p_rent" ,"p_isrent" ,"u_note" ,"r_id" , "isactive"
tab_b--> "rent_id" ,"unit_info_id" ,"t_id" ,"rent_amount" ,"rent_note" ,"rent_date" ,"rent_time" , "r_id"
and my query is as below
SELECT a.* ,
(SELECT SUM(rent_amount)
FROM tab_b
LEFT JOIN tab_a ON tab_b.unit_info_id = tab_a.unit_info_id
WHERE tab_b.rent_date
between '2015-02-03' and '2015-12-03'
GROUP BY tab_b.unit_info_id
) AS "TotalIncome"
FROM tab_a a ,tab_b b
WHERE a.r_id=1 group by a.unit_info_id
when i run above query it gave me duplicate value in totalIncome alias like below image
as per my current data i have rent_amount only for unit_id =1 , in unit_id=2 and unit_id=3 there are no any data in my tab_2 table but when i run above query it gave me output something like above image i need totalIncome as per particular unitwise so any idea how can i solve it?
Aucun commentaire:
Enregistrer un commentaire