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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.