缺少表达式的SQL组

缺少表达式的SQL组,sql,database,group-by,oracle10g,Sql,Database,Group By,Oracle10g,假设我有两个表(属性在括号中) 产品(pid、发布日期、产品名称、价格、说明) 销售(sellid、sellproductid、selluserid、selldate、selltype) 因此,输出将导致以下问题:“显示每次总销售的所有产品”我写了这个SQL查询,但运气不好: select pid, productname, price, count(pid) from products p, sells s having p.pid = s.sellproductid group by pid

假设我有两个表(属性在括号中)

  • 产品(pid、发布日期、产品名称、价格、说明)
  • 销售(sellid、sellproductid、selluserid、selldate、selltype)
  • 因此,输出将导致以下问题:“显示每次总销售的所有产品”
    我写了这个SQL查询,但运气不好:

    select pid, productname, price, count(pid) from products p, sells s having p.pid = s.sellproductid group by pid;
    
    听起来好像group by不起作用,我不知道如何解决这个问题……有什么想法吗?

    试试看

    select pid, producname,price from products p inner join sells s on p.pid=s.sellproductid group by pid.
    
    becouse函数count()返回了一行

    试试看

    select pid, producname,price from products p inner join sells s on p.pid=s.sellproductid group by pid.
    
    becouse函数count()返回了一行

    试试看

    select pid, producname,price from products p inner join sells s on p.pid=s.sellproductid group by pid.
    
    becouse函数count()返回了一行

    试试看

    select pid, producname,price from products p inner join sells s on p.pid=s.sellproductid group by pid.
    

    becouse函数count()返回了一行

    您应该在group by表达式中包含所有非聚合字段。试试这个:

    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
    

    您应该在GROUPBY表达式中包含所有未聚合的字段。试试这个:

    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
    

    您应该在GROUPBY表达式中包含所有未聚合的字段。试试这个:

    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
    

    您应该在GROUPBY表达式中包含所有未聚合的字段。试试这个:

    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
    

    当然我马上就要编辑我的Q了当然。。我马上就要编辑我的Q了当然。。我马上就要编辑我的Q了当然。。我马上就要编辑我的Q了。谢谢你,它真的很有魅力!如果你不介意的话,我可以添加一些东西吗?我如何将每个产品的价格与总销售额相乘,并将它们放在一个新的列中?再次感谢:)谢谢,它像一个魅力!如果你不介意的话,我可以添加一些东西吗?我如何将每个产品的价格与总销售额相乘,并将它们放在一个新的列中?再次感谢:)谢谢,它像一个魅力!如果你不介意的话,我可以添加一些东西吗?我如何将每个产品的价格与总销售额相乘,并将它们放在一个新的列中?再次感谢:)谢谢,它像一个魅力!如果你不介意的话,我可以添加一些东西吗?我如何将每个产品的价格与总销售额相乘,并将它们放在一个新的列中?再次感谢:)ORA-00979不是GROUP BY表达式原因:GROUP BY子句不包含SELECT子句中的所有表达式。group BY子句中必须列出未包含在group函数中的SELECT表达式,例如AVG、COUNT、MAX、MIN、SUM、STDEV或VARIANCE。来源:ORA-00979不是GROUP BY表达式原因:GROUP BY子句不包含SELECT子句中的所有表达式。group BY子句中必须列出未包含在group函数中的SELECT表达式,例如AVG、COUNT、MAX、MIN、SUM、STDEV或VARIANCE。来源:ORA-00979不是GROUP BY表达式原因:GROUP BY子句不包含SELECT子句中的所有表达式。group BY子句中必须列出未包含在group函数中的SELECT表达式,例如AVG、COUNT、MAX、MIN、SUM、STDEV或VARIANCE。来源:ORA-00979不是GROUP BY表达式原因:GROUP BY子句不包含SELECT子句中的所有表达式。group BY子句中必须列出未包含在group函数中的SELECT表达式,例如AVG、COUNT、MAX、MIN、SUM、STDEV或VARIANCE。资料来源: