0

I have two tables reg_dealer and claim_data .

SELECT YEAR(claim_dt) AS `Year`, 
       MONTHNAME(claim_dt) AS `Month`, 
       COUNT(distinct `uniquecode`) AS `No of Reg` 
FROM claim_data
WHERE YEAR(claim_dt) = '2016' 
GROUP BY `Year`, `Month` 
ORDER BY MONTH(claim_dt) DESC


SELECT YEAR(reg_date) AS `Year`, 
       MONTHNAME(reg_date) AS `Month`, 
       COUNT(*) AS `No of Reg`
FROM reg_dealer 
WHERE YEAR(reg_date) = '2016' 
GROUP BY `Year`, `Month` 
ORDER BY MONTH(reg_date)  DESC

i am getting month wise result from both table in same format.

Year----------Month----------No_of_Reg
2016          March           150
2016          February        125
2016          Janurary         75

and i want registration and claim in a one go

Year----------Month----------No_of_Reg---------No_of_claims
2016          March           150                350
2016          February        125                250
2016          Janurary         75                150

also want to get the unique claimants

please help

sba
  • 1,829
  • 19
  • 27

1 Answers1

0

Join the queries.

SELECT t1.Year, t1.Month, `No of Reg`, `No of Claims`
FROM (SELECT YEAR(claim_dt) AS `Year`, MONTHNAME(claim_dt) AS `Month`, MONTH(claim_dt) AS MonthNum, COUNT(distinct `uniquecode`) AS `No of Claims` 
        FROM claim_data 
        WHERE YEAR(claim_dt) = '2016' GROUP BY `Year`, `Month`) AS t1
JOIN (SELECT YEAR(reg_date) AS `Year`, MONTH(claim_dt) AS MonthNum, COUNT(*) AS `No of Reg` 
        FROM reg_dealer 
        WHERE YEAR(reg_date) = '2016' 
        GROUP BY `Year`, `MonthNum`) AS t2
    ON t1.Year = t2.Year AND t1.MonthNum = t2.MonthNum
ORDER BY t1.Year, t1.MonthNum DESC
Barmar
  • 741,623
  • 53
  • 500
  • 612