Jump to content
php.lv forumi

Recommended Posts

Posted (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 by waplet
Posted (edited)
SELECT 
distinct t.niks,
(SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks)
FROM tabula t

?

Edited by Code
Posted

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

Posted (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 by Code
Posted

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

?

Posted

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?

Posted

Jā.

SELECT 
DISTINCT t.niks,
(SELECT count(*) FROM tabula tt WHERE tt.niks = t.niks) as skaits
FROM tabula t
ORDER BY skaits DESC

Posted (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 by waplet
Guest
This topic is now closed to further replies.
×
×
  • Create New...