• 20-01-2014, 03:28:58
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Merhaba Arkadaşlar.Aşağıdaki sorguda ençok alışveriş yapan 10 üyeyi almak istiyorum. purchases tablosundaki top_amount toplayıp ona göre sıralama yapacak sorgu çalışıyor ama çok uzun sürüyor 203.534 sec / 0.016 sec toplam kayıt ise şuan 1400 üye alışveriş purchases ise 5000 satır var yok.

    SELECT customers. * , SUM(top_amount) AS sonuc FROM purchases RIGHT JOIN customers ON customers.id = purchases.`customer_id` GROUP BY customers.id ORDER BY sonuc DESC LIMIT 0, 10
  • 20-01-2014, 03:45:29
    #2
    Bunu çalıştırın

    SELECT customers.*, top_10.total FROM (SELECT customer_id, SUM(top_amount) AS total FROM purchases GROUP BY customer_id LIMIT 0, 10) AS top_10, customers ORDER BY top_10.total DESC
  • 20-01-2014, 03:51:20
    #3
    Khloros adlı üyeden alıntı: mesajı görüntüle
    Bunu çalıştırın

    SELECT customers.*, top_10.total FROM (SELECT customer_id, SUM(top_amount) AS total FROM purchases GROUP BY customer_id LIMIT 0, 10) AS top_10, customers ORDER BY top_10.total DESC
    hocam total'lerin hepsi aynı geldi.
  • 20-01-2014, 03:55:40
    #4
    Kusura bakmayın

    SELECT customers.*, top_10.total FROM (SELECT customer_id, SUM(top_amount) AS total FROM purchases GROUP BY customer_id LIMIT 0, 10) AS top_10, customers WHERE customers.id = top_10.customer_id ORDER BY top_10.total DESC
  • 20-01-2014, 04:05:36
    #5
    Eyvallah Kardeşim