dAivEd Posted June 14, 2010 Report Share Posted June 14, 2010 Sveiks! Man ir tāds jautajums, man datubāze ir: davids davids davids olegs davids igors edgars davids ingus davids ingus Man vajag lai no datubāzes izvada tikai tos vārdus, kuri atkartojas, lai MYSQL izvada šita: daivds davids davids davids davids davids ingus ingus utt.. Kads var palidzēt ar pieprasijumu lai izvēletos tikai tos vardus kuri atkartojas ? Quote Link to comment Share on other sites More sharing options...
briedis Posted June 14, 2010 Report Share Posted June 14, 2010 (edited) Šādi te var atlasīt tikai tos, kas atkārtojas... SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1 ..bet tas gluži nav tas, ko vēlies panākt... EDIT: laikam izštukoju: SELECT * FROM table WHERE name IN (SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1) nav testēts... Edited June 14, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted June 14, 2010 Report Share Posted June 14, 2010 Man vajag lai no datubāzes izvada tikai tos vārdus, kuri atkartojas, lai MYSQL izvada šita: daivds davids davids davids davids davids ingus ingus utt.. Kads var palidzēt ar pieprasijumu lai izvēletos tikai tos vardus kuri atkartojas ? Kam tev taadu marazmu ??? ja gribi saskaitit cik reizes atkartojas tad izmanto cont(*) + HAVING .. GroupBy Quote Link to comment Share on other sites More sharing options...
dAivEd Posted June 14, 2010 Author Report Share Posted June 14, 2010 Šādi te var atlasīt tikai tos, kas atkārtojas... SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1 ..bet tas gluži nav tas, ko vēlies panākt... EDIT: laikam izštukoju: SELECT * FROM table WHERE name IN (SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1) nav testēts... tencinu, un ka man tagad izdzest visus, iznemot 1, lai paliktu davids 1x utt.. ? Quote Link to comment Share on other sites More sharing options...
briedis Posted June 14, 2010 Report Share Posted June 14, 2010 Pag, tev vajag atlasīt visus vārdus, kas atkārtojas? Nu ko tad uzreiz tā neteici! To dara mans pirmais dotais variants - atlasa visus vārdus, kam kopskaits ir > 1... Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted June 14, 2010 Report Share Posted June 14, 2010 To dara mans pirmais dotais variants - atlasa visus vārdus, kam kopskaits ir > 1... Mazliet papildinashu SELECT name, COUNT(name) AS skaits FROM table GROUP BY name HAVING skaits > 1 Shadi varesi dabuut arii skaitu cik tad iisti tas atkartosnas ir P.S. HAVING COUNT(name) Noaminits pret HAVING skaits jo COUNT(name) jau tiek izmantots pashaa selectaa , un itkaa shadi esot "pareizaak" 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.