[英]How can I perform this aggregate?
I have crated two table one is customers and the other one is ord 我创建了两个表,一个是客户,另一个是ord
select * from customers;
id Name age adress salary
2 102 jpj 24 zzzz 10000
3 103 ftd 20 kkkk 20000
4 104 jin 40 llll 30000
5 105 michael 30 dddd 25000
6 106 das 25 hhhh 10000
7 107 vijay 26 mmmm 12000
8 108 thanku 31 jjjj 26000
9 109 vishnu 34 gggg 24000
10 110 vas 28 ffff 18000
select * from ord;
oid order_date id amount
201 12/11/2013 1:00:00 AM 102 2500
202 12/11/2013 4:14:17 AM 102 3000
203 12/9/2013 9:18:16 PM 103 2000
204 12/8/2013 12:00:00 PM 102 1000
using the query 使用查询
select c.name,c.salary,o.amount
from CUSTOMERS c
inner join ord o
on c.id=o.customer_id;
now its print like 现在它的印刷像
1 jpg 10000 1000
2 jpg 10000 3000
3 jpg 10000 2500
4 ftd 20000 2000
5 vijay 12000 2000
But I would like to print my table 但是我想打印我的桌子
name id amount
jpj 102 6500 -> this is the sum of amount in the order table order by 102
ftd 103 2000
vijay 107 2000
please help me to solve this problem I am a starter in sql 请帮助我解决这个问题,我是sql的入门者
You need to group
the data; 您需要对数据进行group
; for example: 例如:
select c.name,c.id,sum(o.amount) as amount
from CUSTOMERS c
inner join ord o on c.id=o.customer_id
group by c.id, c.name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.