Jump to content
php.lv forumi

Nepieciešama palīdzība ar MySQL kveriju


nemakuphp

Recommended Posts

Pagaidām kverijs ir šāds:

 

SELECT a.*, COUNT(c.lauks1) AS count FROM `tabula1` a LEFT JOIN `tabula2` c ON c.lauks2=a.lauks3 GROUP BY a.lauks3, c.lauks2 ORDER BY a.lauks5 ASC

 

Viss notiek, taču ir viena problēma. Kā norādīt, lai viņš pie COUNT ņem vērā tikai tos laukus, no visiem lauks1, kur vērtība ir 1?

 

Varat slēgt, laikam iznāca, taču nezinu vai tā ir pareizi.

 

SELECT a.*, COUNT(c.lauks1) AS count FROM `tabula1` a LEFT JOIN `tabula2` c ON c.lauks2=a.lauks3 AND c.lauks1=1 GROUP BY a.lauks3, c.lauks2 ORDER BY a.lauks5 ASC

 

Ja nav pareizi, palabojiet

Edited by nemakuphp
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...