Herkese Merhaba,
SELECT SUM( test_sonuc ) AS toplam, test_cevapci.user_id
FROM test_cevap, test_cevapci
WHERE test_cevapci.user_id =1234
AND test_cevapci.cevap_id = test_cevap.cevap_id
ORDER BY test_cevap.cevap_id DESC
LIMIT 10
İki tane tablo var
test_cevap:
cevap_id / soru_id / test_sonuc
test_cevapci:
cevapci_id / user_id / cevap_id
Son 10 girdinin toplamını vermesini bekliyorum ama bütün satırların toplamını veriyor. Nedendir acaba?
Mysql LIMIT ve SUM() Sorunu
4
●705
- 04-08-2010, 12:17:43sumda limit olmuyormuş. Şurda birisi iç içe sorgu kullanmış:
http://forums.mysql.com/read.php?10,...543#msg-105543 - 04-08-2010, 14:27:51Üyeliği durduruldu
SELECT SUM( test_cevap_puan ) AS toplam, user_id FROM ( SELECT test_cevap_puan FROM test_cevap, test_cevapcilar WHERE test_cevapcilar.user_id =1234 AND test_cevap.test_cevap_id = test_cevapcilar.test_cevap_id LIMIT 0 , 10 ) AS cc, test_cevapcilar
Kolon ve tablo isimlerini biraz değiştirdim
test_cevap:
test_cevap_id / test_soru_id / test_cevap_puan 1 1 2 2 2 1 3 3 2 4 4 5 5 5 4 6 6 3 7 7 2 8 8 4 9 9 1 10 10 1 11 11 2 12 12 3 13 13 5test_cevapci:
test_cevapci_id / user_id / test_cevap_id 1 1234 1 2 1234 2 3 1234 3 4 5432 4 5 5432 5 6 5432 6 7 1234 7 8 1234 8 9 1234 9 10 1234 10 11 1234 11 12 1234 12 13 1234 13Ben 23 sonucunu vermesini beklerken kod, tamamen alakasız 1125 gibi bir sonuç veriyor.
SELECT SUM( test_cevap_puan ) AS toplam//, user_id FROM ( SELECT test_cevap_puan FROM test_cevap, test_cevapcilar WHERE test_cevapcilar.user_id =1234 AND test_cevap.test_cevap_id = test_cevapcilar.test_cevap_id LIMIT 0 , 10 ) AS cc//, test_cevapcilar
// dan sonraki kısımları silip kodu yukarıdaki şekilde değiştirdiğimde ise son 7 satırı topluyor ve 18 sonucunu veriyor. Aslında son 10 satırı topluyor ama son son 10 satır içinden 7 satır user_id=1234 şartını sağladığı için son 7 satırı topluyor.
Bu cümleciğe 23 sonucunu nasıl verdirebilirim?