27,581
社区成员
发帖
与我相关
我的任务
分享create table tab(id int,name varchar(10))
create table xf(id int,xfje decimal(18,2))
insert tab
select 1,'张三' union
select 2,'李四' union
select 3,'王五'
insert xf
select 1,100.00 union all
select 1,350.00 union all
select 1,150.00 union all
select 2,390.00 union all
select 2,320.00 union all
select 2,150.00 union all
select 2,350.00 union all
select 3,310.00 union all
select 3,200.00 union all
select 3,430.00 union all
select 3,230.00 union all
select 3,150.00
select T1.id 编号,T1.name 姓名,sum(xfje) 消费金额
from tab T1 join
xf T2 ON T1.id=T2.id
group by T1.id ,T1.name
drop table tab,xf
(3 行受影响)
(12 行受影响)
编号 姓名 消费金额
----------- ---------- ---------------------------------------
1 张三 600.00
2 李四 1210.00
3 王五 1320.00
(3 行受影响)
SELECT PI.*,T.Money FROM PI JOIN (
SELECT NO,SUM(ISNULL(Money,0)) AS Money FROM Buy
GROUP BY NO
) T
ON T.NO = PI.NO
select a.NO,a.Pname,sum(isnull(b.Money,0))
from 表一 a,表二 b
where a.NO=b.NO
group by a.NO,a.Pname--还是错误了
select a.NO,a.Pname,sum(isnull(b.Money),0)
from 表一 a,表二 b
where a.NO=b.NO
group by a.NO,a.Pname--修改下
select a.NO,a.Pname,isnull(b.sum(Money),0)
from 表一 a,表二 b
where a.NO=b.NO
group by a.NO,a.Pname select a.*,sum([金额(Money)]
from
表一 a,表二 b
where a.[卡号(No)]=b.[卡号(No)]
group by a.[卡号(No)]select
a.no,a.name,
sum(isnull(b.money,0)) as money
from tb1 as a
left join tb2 as b
on a.no = b.no
group by a.no,a.name