[英]SQL group by missing expression
Assume i have two table (attributes are in parentheses). 假设我有两个表(属性在括号中)。
From this the output will result to this problem: "Show all products with each total sell" 从此输出将导致出现以下问题: “显示每次总销售的所有产品”
I wrote this SQL query with no luck: 我写这个SQL查询没有运气:
select pid, productname, price, count(pid) from products p, sells s having p.pid = s.sellproductid group by pid;
Sound like the group by is not working, with sql minor knowledge i can't understand how to fix this...any idea? 听起来好像group by不能正常工作,具有sql的小知识,我不明白如何解决此问题...任何想法?
You should include all the non-aggregated fields in the group by expression. 您应按表达式将所有非聚合字段包括在内。 Try This:
尝试这个:
select pid, productname, price, count(1) as ProductsSold,count(1)*price as Income
from products p, sells s
where p.pid = s.sellproductid
group by pid, productname, price
try 尝试
select pid, producname,price from products p inner join sells s on p.pid=s.sellproductid group by pid.
becouse function count() returned one row. 因为函数count()返回了一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.