表A:
uid dat
01 060801
02 060801
03 060801
04 060802
05 060802
06 060803
07 060804
表B:
uid pluid amt
01 11 1
01 12 2
02 12 1
03 13 2
04 12 1
05 13 2
06 11 1
07 12 2
求:
dat sum(amt)
060801 6
060802 3
060803 1
060807 2就是想根据A中的时间DAT把当天的销售总数做出来!
uid dat
01 060801
02 060801
03 060801
04 060802
05 060802
06 060803
07 060804
表B:
uid pluid amt
01 11 1
01 12 2
02 12 1
03 13 2
04 12 1
05 13 2
06 11 1
07 12 2
求:
dat sum(amt)
060801 6
060802 3
060803 1
060807 2就是想根据A中的时间DAT把当天的销售总数做出来!
from a,b
where a.uid=b.uid
group by a.dat
order by a.dat
insert A
select '01','060801' union all
select '02','060801' union all
select '03','060801' union all
select '04','060802' union all
select '05','060802' union all
select '06','060803' union all
select '07','060804'
--select * from Acreate table B(uid char(2),pluid int,amt int)
insert B
select '01', 11, 1 union all
select '01', 12, 2 union all
select '02', 12, 1 union all
select '03', 13, 2 union all
select '04', 12, 1 union all
select '05', 13, 2 union all
select '06', 11, 1 union all
select '07', 12, 2
--select * from Bselect
A.dat,
sum(B.amt) as [sum(amt)]
from B inner join A on
B.uid=A.uid
group by A.datdrop table A,B
from A
inner join B
on A.uid=B.uid
group by A.dat