• 16-05-2018, 00:39:55
    #1
    database ve sql 'da yeniyim yardımcı olacak olursa sevinirim.

    productInformation
    -productInformationID(primarykey)
    -..
    -price


    products
    -productId (primary key)
    -productInformationID (foreign key)
    -...
    -..

    soldProducts
    -id(primarykey)
    -product(foreignkey)


    amacım en çok satılan product'ın toplam price'ını bulmak. bu sql sorgusuu nasıl yapabilirim yardımcı olabilecek var mı acaba.
  • 16-05-2018, 01:15:21
    #2
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Aklıma ilk geldiği şekilde yazmaya çalıştım daha kolayı vardır belki ama, işinizi görebilir hocam

    SELECT productId,( (SELECT count(*) FROM `soldProducts` GROUP BY product ORDER BY count(*) DESC LIMIT 1) * (SELECT price FROM `productInformation` WHERE productInformationID = (SELECT productInformationID FROM `product` WHERE productId = (SELECT product FROM `soldProducts` GROUP BY product ORDER BY count(*) DESC LIMIT 1) LIMIT 1)) ) as toplamSatis FROM product LIMIT 1
  • 16-05-2018, 01:18:12
    #3
    Sahurlu gözlerle yazdım ben de bilmem çalışır mı

    SELECT pi.price, count(*) FROM SOLDPRODUCTS sp
    INNER JOIN PRODUCT p ON sp.product = productId
    INNER JOIN PRODUCTINFORMATION pi ON pi.productInformationID = p.productInformationID
    group by sp.product
    ORDER BY count(*) DESC LIMIT 1
  • 16-05-2018, 02:01:38
    #4
    Veritabanını oluşturup test ettim hocam çalışıyor, hayırlı sahurlar

    Select a.adet * c.price as tutar From (
    Select Top 1
    max(product) as product,
    count(*) as adet ,
    ROW_NUMBER() OVER (ORDER BY count(*) desc) as row
    from soldProducts
    group by product
    order by count(*) desc) As a
    inner join product as b on a.product = b.productId
    inner join productInformation as c on c.productInformationID = b.productInformationID
  • 16-05-2018, 02:05:59
    #5
    AhmetTulgar adlı üyeden alıntı: mesajı görüntüle
    Aklıma ilk geldiği şekilde yazmaya çalıştım daha kolayı vardır belki ama, işinizi görebilir hocam

    SELECT productId,( (SELECT count(*) FROM `soldProducts` GROUP BY product ORDER BY count(*) DESC LIMIT 1) * (SELECT price FROM `productInformation` WHERE productInformationID = (SELECT productInformationID FROM `product` WHERE productId = (SELECT product FROM `soldProducts` GROUP BY product ORDER BY count(*) DESC LIMIT 1) LIMIT 1)) ) as toplamSatis FROM product LIMIT 1
    hocam cok tesekkür ettim calısmasa bile izlediginiz yol yardımcı oluyor.
    maviuan adlı üyeden alıntı: mesajı görüntüle
    Sahurlu gözlerle yazdım ben de bilmem çalışır mı

    SELECT pi.price, count(*) FROM SOLDPRODUCTS sp
    INNER JOIN PRODUCT p ON sp.product = productId
    INNER JOIN PRODUCTINFORMATION pi ON pi.productInformationID = p.productInformationID
    group by sp.product
    ORDER BY count(*) DESC LIMIT 1
    aynı sekilde hocam cok tesekkür ediyorum.
    Scythe2112 adlı üyeden alıntı: mesajı görüntüle
    Veritabanını oluşturup test ettim hocam çalışıyor, hayırlı sahurlar

    Select a.adet * c.price as tutar From (
    Select Top 1
    max(product) as product,
    count(*) as adet ,
    ROW_NUMBER() OVER (ORDER BY count(*) desc) as row
    from soldProducts
    group by product
    order by count(*) desc) As a
    inner join product as b on a.product = b.productId
    inner join productInformation as c on c.productInformationID = b.productInformationID
    hocam ben postgresql kullanıyorum bunu belirtmem gerekliydi sanırım ben de bu yuzden mi calısmadı acaba. max kısmında bir hata aldım.

    çok teşekkür ederim yardımınız için
  • 16-05-2018, 02:30:08
    #6
    coderlara bak dayanamayıp yazmışlar sahur falan hak getire hocam postgresql inner join diye aratin kendinize uyarlayıp uygulayın. cozersiniz.
  • 16-05-2018, 02:49:26
    #7
    ermanaltind adlı üyeden alıntı: mesajı görüntüle
    coderlara bak dayanamayıp yazmışlar sahur falan hak getire hocam postgresql inner join diye aratin kendinize uyarlayıp uygulayın. cozersiniz.
    aynen hocam sagolsunlar su destek stackoverflow da dahi olamazdı sanırım
    sizin de bahsettiginiz inner join olayı kafamdaki bazı soru isaretlerini giderdi sagolun tavsiye için bi şekilde cozmeye calısıyorum.