avatar
问关于group by的问题# Database - 数据库
D*r
1
My table has following fields:
OrderID, Customer, Price, Quantity
Then how I can get the total price by Customer for all Customers?
Thanks in advance.
avatar
t*s
2
select Customer, sum(Price) from YourTable
group by Customer

【在 D*******r 的大作中提到】
: My table has following fields:
: OrderID, Customer, Price, Quantity
: Then how I can get the total price by Customer for all Customers?
: Thanks in advance.

avatar
r*y
3
You didn't count the quantity ah.
What I want is like sum(price*quantity) group by customer
but cannot use sum(price*quantity), it does not work since price*quantity is
not a column.
any advice?

【在 t*****s 的大作中提到】
: select Customer, sum(Price) from YourTable
: group by Customer

avatar
m*g
4
create an extra view

【在 r****y 的大作中提到】
: You didn't count the quantity ah.
: What I want is like sum(price*quantity) group by customer
: but cannot use sum(price*quantity), it does not work since price*quantity is
: not a column.
: any advice?

avatar
m*g
5
forget it, I just found you can use
SELECT Customer, SUM(Price * Quantity) AS Prices
FROM dbo.Table1
GROUP BY Customer

【在 m*****g 的大作中提到】
: create an extra view
avatar
t*s
6
select Customer, Total = sum(Price*Quantity) from YourTable
group by Customer

【在 r****y 的大作中提到】
: You didn't count the quantity ah.
: What I want is like sum(price*quantity) group by customer
: but cannot use sum(price*quantity), it does not work since price*quantity is
: not a column.
: any advice?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。