簡體   English   中英

列“d.discount_amount”必須出現在 GROUP BY 子句中或用於聚合函數中

[英]column “d.discount_amount” must appear in the GROUP BY clause or be used in an aggregate function

我編寫了此查詢以使用兩個不同的表查找付款,

SELECT (SUM(o_p.price) - d.discount_amount) as payment
FROM order_products as o_p
LEFT JOIN discounts as d  ON O_p.order_id = d.order_id
GROUP BY o_p.order_id

它顯示錯誤列“d.discount_amount”必須出現在 GROUP BY 子句中或用於聚合函數 LINE 1: SELECT o_p.order_id, (SUM(price) - d.discount_amount) as pay...

晚上 9:23

請問有什么建議嗎?

select t1.sm - t2.discount_amount
  from (
select t1.order_id,
       sum(t1.price) sm
  from order_products t1
 order by t1.order_id) t1 left join discounts t2 on t1.order_id = t2.order_id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM