Jump to content

COUNT, Group By with LEFT JOIN and JOIN


AlexHWGUY

Recommended Posts

SELECT s.siteName, count(p.posNo) as nbPos
FROM site s
LEFT JOIN pos p ON s.siteId = p.siteId
AND posDTime >= CONVERT_TZ(TIMESTAMP('2009-03-01'),'SYSTEM','GMT')
AND posDTime <= DATE_ADD(CONVERT_TZ(TIMESTAMP('2009-03-04'),'SYSTEM','GMT'), INTERVAL 1 DAY)

AND p.mobileId IN (SELECT mobileId FROM callsign WHERE cieNo = '5')
/*JOIN callsign c ON c.mobileId = cp.mobileId AND c.cieNo = '5'*/

GROUP BY s.siteId ORDER BY nbPos DESC

 

Table : pos, site, callsign

This query return the number of "Position (pos)" per site for a Periode and a Cie

 

It's working but I think the sub-query slow query time.

Is there a way to integrate the "JOIN callsign" in the query without loosing count=0 results ?

 

Thanks !

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/151908-count-group-by-with-left-join-and-join/
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.