简体   繁体   English

列“d.discount_amount”必须出现在 GROUP BY 子句中或用于聚合函数中

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

I have written this query to find the payment using two different table ,我编写了此查询以使用两个不同的表查找付款,

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

It shows an error column "d.discount_amount" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT o_p.order_id, (SUM(price) - d.discount_amount) as pay...它显示错误列“d.discount_amount”必须出现在 GROUP BY 子句中或用于聚合函数 LINE 1: SELECT o_p.order_id, (SUM(price) - d.discount_amount) as pay...

9:23 PM晚上 9:23

Any suggestions, please?请问有什么建议吗?

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.

相关问题 SQL:列必须出现在 GROUP BY 子句中或在聚合函数中使用 - SQL: Column Must Appear in the GROUP BY Clause Or Be Used in an Aggregate Function postgres-SELECT / GROUP BY中的部分列-列必须出现在GROUP BY子句中或在聚合函数中使用 - postgres - partial column in SELECT/GROUP BY - column must appear in the GROUP BY clause or be used in an aggregate function 无效操作:列“[column_name]”必须出现在 GROUP BY 子句中或在聚合 function 中使用; - Invalid operation: column “[column_name]” must appear in the GROUP BY clause or be used in an aggregate function; 必须出现在GROUP BY子句中或在聚合函数中使用(PostgreSQL) - Must appear in the GROUP BY clause or be used in an aggregate function (PostgreSQL) PGError:错误:列“ inboxes.id”必须出现在GROUP BY子句中或在聚合函数中使用 - PGError: ERROR: column “inboxes.id” must appear in the GROUP BY clause or be used in an aggregate function SQL:必须出现在GROUP BY子句中或在聚合函数中使用 - SQL: Must appear in the GROUP BY clause or be used in an aggregate function GROUP BY子句必须与聚合函数一起使用吗? - The GROUP BY clause must be used with aggregate functions? 选定的项目不必出现在 GROUP BY 子句中或用于聚合 function - selected items don't have to appear in the GROUP BY clause or be used in an aggregate function 当 select 列不是聚合 function 也不在 group by 子句中时不会出现错误 - Not getting an error when select a column that is not an aggregate function nor in the group by clause invalid:聚合函数或GROUP BY子句 - invalid : aggregate function or the GROUP BY clause
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM