andrisp Posted April 19, 2005 Report Share Posted April 19, 2005 Piem kolumna: USER_ID 2055 2034 2022 2055 2034 2034 2022 vajag taadu kveriju, kas panjem tikai taas rindas ar vienaadiem USER_ID, kuru kopskaits ir vairaak nekaa citaam rindaam ar vienaadiem USER_ID. Shajaa gadijumaa tas buutu 2034. Link to comment Share on other sites More sharing options...
Delfins Posted April 19, 2005 Report Share Posted April 19, 2005 (edited) Piem kolumna:USER_ID 2055 2034 2022 2055 2034 2034 2022 vajag taadu kveriju, kas panjem tikai taas rindas ar vienaadiem USER_ID, kuru kopskaits ir vairaak nekaa citaam rindaam ar vienaadiem USER_ID. Shajaa gadijumaa tas buutu 2034. 16636[/snapback] select count(user_id) AS cnt from users group by user_id having count(user_id) > 1 order by cnt desc limit 1 ??? PS: netesteju bet vajadzetu buut ok Edited April 19, 2005 by Delfins Link to comment Share on other sites More sharing options...
bubu Posted April 19, 2005 Report Share Posted April 19, 2005 Kam tur to HAVING vajag? Vai nevar vienkārši: SELECT user_id FROM tabule GROUP BY user_id ORDER BY COUNT(user_id) LIMIT 1 Link to comment Share on other sites More sharing options...
Delfins Posted April 19, 2005 Report Share Posted April 19, 2005 Kam tur to HAVING vajag?Vai nevar vienkārši: SELECT user_id FROM tabule GROUP BY user_id ORDER BY COUNT(user_id) LIMIT 1 16638[/snapback] labi labi, bet taapat labojums select user_id, count(user_id) AS cnt from users group by user_id order by cnt desc limit 1 Link to comment Share on other sites More sharing options...
andrisp Posted April 19, 2005 Author Report Share Posted April 19, 2005 tad kad es pielieku ORDER BY COUNT(user_id) klaat, man izlec Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment Share on other sites More sharing options...
Delfins Posted April 19, 2005 Report Share Posted April 19, 2005 tad kad es pielieku ORDER BY COUNT(user_id) klaat, man izlec Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource 16645[/snapback] izmanto to kas man pēdējā postā. PS: kad raksti querijus, labāk tos pārbaudi iekš konsoles vai kāda cita klienta... vai sliktākajā gadījumā mysql_error() izvadi Link to comment Share on other sites More sharing options...
andrisp Posted April 19, 2005 Author Report Share Posted April 19, 2005 paldies Delfin, nostraadaaja perfekti. un paldies par padomu sleegties pa taisno pie mysql servera caur konsoles, mazaak chakareeshanaas sanaak :) Link to comment Share on other sites More sharing options...
Delfins Posted April 19, 2005 Report Share Posted April 19, 2005 paldies Delfin, nostraadaaja perfekti. un paldies par padomu sleegties pa taisno pie mysql servera caur konsoles, mazaak chakareeshanaas sanaak :) 16647[/snapback] da tas `order by funkcija(lauks)` + grouping laikam tikai postgre/oracle straadaa.. (ja kļūdos, pielabojiet) Link to comment Share on other sites More sharing options...
v3rb0 Posted April 19, 2005 Report Share Posted April 19, 2005 da tas `order by funkcija(lauks)` + groupinglaikam tikai postgre/oracle straadaa.. (ja kļūdos, pielabojiet) 16649[/snapback] tieši tā, mysql šitais nestrādā. viens workraunds ir izmantot salikto kveriju. neko nepārbaudot, kaut kā šita aptuveni tas izskatītos select s1.user_id as user_id from ( SELECT user_id as user_id, COUNT(user_id) as cnt FROM tabule GROUP BY user_id ) s1 ORDER BY s1.cnt LIMIT 1 Link to comment Share on other sites More sharing options...
Recommended Posts