anonīms Posted March 21, 2013 Report Share Posted March 21, 2013 (edited) Ir datubāzes tabula km1, km2, km1_rez, km2_rez Ir Komanda ar ID 10 piemēram. Ir ntās spēles savadītas tabulā, bet ir nepieciešams iegūt tikai datus no pēdējām 10 spēlēm, kur ir piedalījusies šī komanda. Itkā mēģināju ar LIMIT, bet viņš skaita arī spēles, kas ir virs 10tā NUMROW'a. Mazs piemērs kā mēģināju post edit sux ;[ http://paste.php.lv/a6cb98cd7ae5d526f917a2c74a92cb39?lang=php Mērķis ir iegūt uzvaru/zaudējumu skaitu no pēdējām 10 spēlēm. Šis kverijs man izvada stdClass Object([L10_wins] => 9[L10_lost] => 8) kgan nepieciešams piemēram stdClass Object([L10_wins] => 6[L10_lost] => 4) Edited March 21, 2013 by anonīms Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted March 21, 2013 Report Share Posted March 21, 2013 Jo tev ir 2 subselekti, kur katram ir limit 10, kopā 20 ieraksti var atlasīties. Pastāv jau tāda lieta kā OR un AND ... SELECT `lauki` FROM `tabula` WHERE (km1=komanda AND km1_rez>km2_rez) OR (km2=komanda AND km2_rez>km1_rez) AND ... LIMI 10 ... Quote Link to comment Share on other sites More sharing options...
anonīms Posted March 22, 2013 Author Report Share Posted March 22, 2013 nebūs īstā štelle. Pat mēģinot parastu kveriju SELECT COUNT( * ) FROM ****_spelesWHERE ligas_id =1AND km1 =22AND km1_rez > km2_rezLIMIT 10viņš vienkārši nekaunot tad vairāk par 10, ja ir limit's, bet tas nestrādā kā offsets vai kas tāds Quote Link to comment Share on other sites More sharing options...
spainis Posted March 22, 2013 Report Share Posted March 22, 2013 select count(*) from ( select `km1_rez`, `km2_rez` from `...` where (`km1` = ... or `km2` = ...) order by `id` desc limit 10 ) as t where `km1_rez` > `km2_rez` Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted March 22, 2013 Report Share Posted March 22, 2013 Tā varētu būt, jo limit darbojas uz galarezultātu. Kaut kas tāds neder? SELECT COUNT( * ) FROM ( SELECT * FROM ****_speles WHERE ligas_id =1 AND km1 =22 AND km1_rez > km2_rez LIMIT 10 ); Quote Link to comment Share on other sites More sharing options...
anonīms Posted March 22, 2013 Author Report Share Posted March 22, 2013 (edited) Diemžēl nēTavs kverijs: "every derived table must have its own alias" so... SELECT COUNT( * ) AS t1FROM (SELECT * FROM bliezamv3_ligas_spelesWHERE ligas_id =1AND km1 =22AND km1_rez > km2_rezLIMIT 10) AS t2 t110 mļe, laikam būs php pusē jāapstrādā :/ EDIT: ieraudzīju spaiņa komentāru. Nočekošu Edited March 22, 2013 by anonīms Quote Link to comment Share on other sites More sharing options...
anonīms Posted March 22, 2013 Author Report Share Posted March 22, 2013 Izskatās, ka spaiņa variants strādā. select count(*) AS wins from ( select `km1_rez`, `km2_rez`,`km1`, `km2` from `bliezamv3_ligas_speles` where (`km1` = 22 or `km2` = 22) order by `id` desc limit 10 ) as t where `km1` = 22 AND `km1_rez` > `km2_rez` W - 6 Tencinu. Pielikšu te vēl zaudējumus un tad ziņošu par notiekošo :) Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted March 22, 2013 Report Share Posted March 22, 2013 Arī, ja km2 ir tevis meklētā komanda un viņi ir uzvarējuši? Quote Link to comment Share on other sites More sharing options...
anonīms Posted March 22, 2013 Author Report Share Posted March 22, 2013 (edited) Nezinu, es atmetu ar roku šai domai un paklausīju kolēģi :D http://paste.php.lv/205dc781ca31c3e8db57d8e393aecd92?lang=php es padomāju, ka varbūt ar tas 1 kverijs tomēr būs ātrāk nekā tie subkveriji visādi Edited March 22, 2013 by anonīms 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.