我需要创建以下表模式的一般报告:
我需要为常规报告创建以下表格:
+----------+--------+------------------+-----------------------------+------------------------------+
| Location | Trucks | TotalOfCampaings | CampaingsWithCompleteStatus | CampaingsWithInProcessStatus |
+----------+--------+------------------+-----------------------------+------------------------------+
| | | | | |
+----------+--------+------------------+-----------------------------+------------------------------+
| | | | | |
+----------+--------+------------------+-----------------------------+------------------------------+
广告投放=订购一辆或多辆卡车。
我尝试了内部联接,但我无法获得对一般报告的期望。
非常感谢帮助我,关于评论的任何问题!
答案 0 :(得分:4)
SELECT Truck.location as Location,
COUNT(Truck.vin) as Trucks,
COUNT(Campaing.campaing_id) as TotalOfCampaings,
sum(case when Campaing.campaing_estatus = 'Complete' then 1 else 0 end) as CampaingsWithCompleteStatus,
sum(case when Campaing.campaing_estatus = 'InProcess' then 1 else 0 end) as CampaingsWithInProcessStatus
FROM CampaingControl
INNER JOIN Truck ON CampaingControl.vin = Truck.vin
INNER JOIN Campaing ON CampaingControl.campaing_id = Campaing.campaing_id
GROUP BY Truck.location;