waplet Posted July 29, 2010 Report Share Posted July 29, 2010 (edited) ir datubāze.. mape - niks lala | waplet lala1 | waplet epic | vilis . utt un vajag dabūt kko šadu dabūt daudzumu lietotājiem cik ir mapes katram, pie nosacījuma, ka lietotājam ir vismaz viena mape. izvade - #1 waplet - 2 #2 vilis - 1 ps. edit: Ā nē.. nevajag nosacījumu, vajag vnk dabūt skaitu cik lauciņam "niks" ir dazādu "mape". Edited July 29, 2010 by waplet Link to comment Share on other sites More sharing options...
Code Posted July 29, 2010 Report Share Posted July 29, 2010 (edited) SELECT distinct t.niks, (SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks) FROM tabula t ? Edited July 29, 2010 by Code Link to comment Share on other sites More sharing options...
waplet Posted July 29, 2010 Author Report Share Posted July 29, 2010 A drīkst - ? SELECT t.niks, (SELECT count(*) FROM tabula t WHERE t.niks = t.niks) FROM tabula t , jo te es skatos no citas tabulas paņem lietotājus un tad ar tiem cauri braukā.. , bet man vajag no self tabulas.. saskaītit cik katram ir mapes. + vel nebūs.. tāds, kuram būs 0.. jo tur kā primary ir mape nevis niks SELECT t.niks, (SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks) FROM tabula t Link to comment Share on other sites More sharing options...
Code Posted July 29, 2010 Report Share Posted July 29, 2010 (edited) Tabula ir tā pati, vienkārši alias cits. (neaizmirsti distinct) Tāds, kuram būtu 0 tiešām nebūs, tad vajag atsevišķu tabulu ar lietotājiem, jo nevar saskaitīt mapes lietotājam, kurš neeksistē tabulā. Edited July 29, 2010 by Code Link to comment Share on other sites More sharing options...
waplet Posted July 29, 2010 Author Report Share Posted July 29, 2010 Ak jā.. nedaudz pāpratu kvēriju (tmi) mana vaina.. A kur tieši distinctu? SELECT DISTINCT t.niks, (SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks) FROM tabula t ? Link to comment Share on other sites More sharing options...
Code Posted July 29, 2010 Report Share Posted July 29, 2010 Nu, jā - skat. manu pirmo postu. Ja nebūs distincts, tad niki atkārtosies. Link to comment Share on other sites More sharing options...
waplet Posted July 29, 2010 Author Report Share Posted July 29, 2010 A drīkst to SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks , kkā taka piešķirt mainīgu un tad ORDER by countmainigais DESC? Link to comment Share on other sites More sharing options...
Code Posted July 29, 2010 Report Share Posted July 29, 2010 Jā. SELECT DISTINCT t.niks, (SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks) as skaits FROM tabula t ORDER BY skaits DESC Link to comment Share on other sites More sharing options...
waplet Posted July 29, 2010 Author Report Share Posted July 29, 2010 (edited) ahh :D Cik es tomēr pats attapīgs biju $query = mysql_query(" SELECT distinct t.jumper, (SELECT count(*) FROM db_demos tt WHERE tt.jumper = t.jumper) as count FROM db_demos t ORDER BY skaits DESC LIMIT 15" ); Paldies. Klapējam ciet. Edited July 29, 2010 by waplet Link to comment Share on other sites More sharing options...
Recommended Posts