Jump to content
php.lv forumi

Recommended Posts

Posted

Ar šo es varu atlasīt pirkumus pēc to biežuma:

Select count(*) as total_count, id,email from orders group by email order by total_count desc

 

Viss strādā. Bet man NEVAJAG atlasīt visus ierakstus, man vajag tikai tos, kas ir veikuši pirkumus vairāk kā divas reizes. Selects varētu būt šāds, bet nestrādā:

Select count(*) as total_count, id,email from orders where total_count>'2' group by email order by total_count desc

Posted (edited)

Ar šādu kveriju tu neselekto atgriezto ierakstu skaitu, bet gan tikai tos ierakstus, kuriem total_count laukā vērtība ir lielāka par 2.

Veic pārbaudi, izmantojot mysql_num_rows().

Edited by kechums
Posted

aiz "group by email" pieraksti "having total_count > 2" vai kāda nu tev tur ir tā matemātika vajadzīga. Tb uzsvars uz "HAVING" izmantošanu

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