nascar Posted October 15, 2011 Report Share Posted October 15, 2011 Sveiki, lieta tāda ka man iekš DB tabula ir 30 komandas, tālāk es ar šo gribu izvilkt komandas vietu tabulā pēc "pts" Kods: $team_ranks = mysql_query("SELECT *, pts AS myteamrank, (SELECT COUNT(DISTINCT(pts)) FROM tabula WHERE pts>myteamrank) AS teamrank FROM tabula WHERE team_saisinajums = '".$_GET['team_saisinajums']."'") or die(mysql_error()); $team_rank = mysql_fetch_array($team_ranks); Un izvadu kā: <?=$team_rank['teamrank'];?> Kapēc viņš man izvada visām 30 komandām "1" vietu? Pēc būtības jabūt no 1 > 30, selektojot pēc pts... Ceru ka sapratāt, ko vēlos jums pateikt. Paldies, Kaspars. Link to comment Share on other sites More sharing options...
codez Posted October 15, 2011 Report Share Posted October 15, 2011 (edited) ... SELECT COUNT(*) ... Edited October 15, 2011 by codez Link to comment Share on other sites More sharing options...
nascar Posted October 15, 2011 Author Report Share Posted October 15, 2011 Es izdariju tā, bet rāda tagad Reference 'myteamrank' not supported (reference to group function) mysql_query("SELECT COUNT(*) AS myteamrank, (SELECT COUNT(DISTINCT(pts)) FROM tabula WHERE pts>myteamrank) AS teamrank FROM tabula WHERE team_saisinajums = '".$_GET['team_saisinajums']."' GROUP BY pts") or die(mysql_error()); Es pieliku tagad grupu klāt, bet tāpatas nekādas izmaiņas... ES uzreiz saku es ar Grupām nēsmu saskārsies... Link to comment Share on other sites More sharing options...
codez Posted October 15, 2011 Report Share Posted October 15, 2011 SELECT *, pts AS myteamrank, (SELECT COUNT(*) FROM tabula WHERE pts>myteamrank) AS teamrank FROM tabula WHERE team_saisinajums='123' Link to comment Share on other sites More sharing options...
nascar Posted October 15, 2011 Author Report Share Posted October 15, 2011 Vienalga izvelk, visiem '1' numuru. Link to comment Share on other sites More sharing options...
codez Posted October 15, 2011 Report Share Posted October 15, 2011 (edited) Uztaisīju tabulu t2 ar laukiem id,pts. Savadīju pāris vērtība un šis kverijs strādā pareizi: SELECT *,pts as mypts, (SELECT count(*) as rank FROM t2 WHERE pts>mypts) as myrank FROM t2 WHERE id=300 Edited October 15, 2011 by codez Link to comment Share on other sites More sharing options...
nascar Posted October 15, 2011 Author Report Share Posted October 15, 2011 Ā, nu man arī iet. Paldies, codez. TC. Link to comment Share on other sites More sharing options...
Recommended Posts