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:
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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.