0

I have a table consisting of customer purchase records having following columns

CUSTOMER  TRANSDATE  SALENUM  STORE  TRANSTYP  PRICE  
--------  --------- --------- ----- --------- ------
  1     12-FEB-2013    777      O     CASH      7.99
  1     12-FEB-2013    777      O     CASH      6.99
  1     12-FEB-2013    778      O     CARD      9.17
  2     23-APR-2013    987      D     CASH      7.65
  1     15-MAY-2013    1098     T     CARD      2.35

I want to aggregate over salenum i,e for each salenum, i want the total price, as well as the store, transtyp, transdate,customer values as these are same for a particular salenum

However if i use

select customer,transdate,salenum,store,transtyp,sum(price) from table1 group by salenum

Its obviously saying not a valid group by value. How to get the desired result?

SAMPLE RESULT:

CUSTOMER  TRANSDATE  SALENUM  STORE  TRANSTYP  PRICE  
--------  --------- --------- ----- --------- ------
  1     12-FEB-2013    777      O     CASH      15.98
  1     12-FEB-2013    778      O     CARD       9.17
4

2 回答 2

1

所有非聚合列应按以下方式分组:

select customer,transdate,salenum,store,transtyp,sum(price)
from table1 
group by customer,transdate,salenum,store,transtyp
于 2013-06-14T01:46:07.167 回答
0
SELECT CUSTOMER,TRANSDATE,SALENUM,STORE,TRANSTYP,SUM(PRICE)
FROM TABLE1
GROUP BY CUSTOMER,TRANSDATE,SALENUM,STORE,TRANSTYP
ORDER BY CUSTOMER

I using the order by clause because it will be in order and also in sequence.

于 2013-06-14T01:51:37.157 回答