jupper Posted September 9, 2009 Report Share Posted September 9, 2009 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 Quote Link to comment Share on other sites More sharing options...
kechums Posted September 9, 2009 Report Share Posted September 9, 2009 (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 September 9, 2009 by kechums Quote Link to comment Share on other sites More sharing options...
jupper Posted September 9, 2009 Author Report Share Posted September 9, 2009 man jau vajag dabūt tikai tos, kas lielāki par 2, bet tāds querijs izmet kļūdu, ka mysql sintakse nepareiza Quote Link to comment Share on other sites More sharing options...
Kaklz Posted September 9, 2009 Report Share Posted September 9, 2009 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 Quote Link to comment Share on other sites More sharing options...
jupper Posted September 10, 2009 Author Report Share Posted September 10, 2009 Paldies, ar "HAVING" viss aizgāja Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.