2016-10-14 6 views
0

"BESTELLING_ID"ごとの合計価格を計算しようとしています。しかし、私はどこから始めるべきかわかりません。 bestelling_idでグループ化することはうまくいきません。ここでは、 "BESTELLING_ID"ごとに計算の値を合計するクエリの結果を確認できます。私は他の質問を見ようとしていましたが、私の質問に答えを関連づけることはできません。私は注文ごとの個人的な注文額を示すチャートにこれを使用したいと思います。前もって感謝します。別の列を別の列でグループ化するよう選択してください

BESTELLING_ID NAAM ((P.PRIJS)*(R5.GEWICHT/100)) 
1    ui     .25 
1    pindakaas    1.7 
22    Broccoli    1 
22    Rijst     1 
select b.bestelling_id ,p.naam, ((p.prijs)* (r5.gewicht/100)) 
    from relation_6 r6 
    join bestellingregel br on br.dieet_dieet_id= r6.dieet_id 
    join bestelling b on br.bestelling_id=b.bestelling_id 
    join relation_5 r5 on r5.recept_recept_id= r6.recept_id 
    join product p on p.product_id = r5.product_product_id 
    where p.winkelbeheer_winkelbeheer_id=2 
    order by b.datum 
; 

答えて

1

使用この:

select 
     a.col1 as BESTELLING_ID,sum(a.col3) as Total_Price 
from (  
    SELECT b.bestelling_id col1, p.naam col2, ((p.prijs) * (r5.gewicht/100)) col3 
    FROM relation_6 r6 
     JOIN bestellingregel br ON br.dieet_dieet_id = r6.dieet_id 
     JOIN bestelling b ON br.bestelling_id = b.bestelling_id 
     JOIN relation_5 r5 ON r5.recept_recept_id = r6.recept_id 
     JOIN product p ON p.product_id = r5.product_product_id 
    WHERE p.winkelbeheer_winkelbeheer_id = 2 
ORDER BY b.datum) a 
group by a.col1; 
+0

ありがとうございました!私は、これが実際にどのように機能するかを簡単に調べるために、これを試してみる必要があります。しかし今のところ、これは私を助けてくれます! – Colivar

0

あなたは、サブクエリを必要としないだけでgroup by

select b.bestelling_id, sum((p.prijs)* (r5.gewicht/100)) 
from relation_6 r6 join 
    bestellingregel br 
    on br.dieet_dieet_id = r6.dieet_id join 
    bestelling b 
    on br.bestelling_id = b.bestelling_id join 
    relation_5 r5 
    on r5.recept_recept_id = r6.recept_id join 
    product p 
    on p.product_id = r5.product_product_id 
where p.winkelbeheer_winkelbeheer_id = 2 
group by b.bestelling_id; 

あなたがでp.naamを含めることができるかもしれselectおよびgroup byとし、 reはbestselling_idごとに1つの名前です。

関連する問題