日期:2014-05-17 浏览次数:20654 次
select a.uid,sum(b.money) from table2 a left join table1 b gruop by a.uid
------解决方案--------------------
不怎么清晰的感觉。。。
table1的uid是有重复的 那到时候算总消费依据什么呢
额 或许我理解能力不够高啊
------解决方案--------------------
select sum([money]),uid summoney from table1 where uid in
(select uid from table2)
group by table1.uid
------解决方案--------------------
select sum([money]),a.uid summoney from table1 as a join table2 as b on a.uid =b.uid group by a.uid
------解决方案--------------------
create table #T ( [ID] int identity(1,1) NOT NULL, [uid]int NULL, [money] decimal(12,2) NULL ) INSERT INTO #T SELECT 2, 3 union all SELECT 2 ,5 union all SELECT 1, 5 union all SELECT 8, 3 union all SELECT 5, 10 union all SELECT 3, 20 union all SELECT 8, 6 union all SELECT 6, 9 union all SELECT 8, 3 union all SELECT 1, 60 union all SELECT 3, 8 union all SELECT 3, 5 union all SELECT 5, 6 union all SELECT 2, 10 union all SELECT 3, 10 SELECT DISTINCT uid,SUM(money)OVER(PARTITION BY uid ) Ssum FROM #t drop table #T (15 行受影响) uid Ssum ----------- --------------------------------------- 1 65.00 2 18.00 3 43.00 5 16.00 6 9.00 8 12.00 (6 行受影响)
------解决方案--------------------
貌似这个快很多
create table #T ( [ID] int identity(1,1) NOT NULL, [uid]int NULL, [money] decimal(12,2) NULL ) INSERT INTO #T SELECT 2, 3 union all SELECT 2 ,5 union all SELECT 1, 5 union all SELECT 8, 3 union all SELECT 5, 10 union all SELECT 3, 20 union all SELECT 8, 6 union all SELECT 6, 9 union all SELECT 8, 3 union all SELECT 1, 60 union all SELECT 3, 8 union all SELECT 3, 5 union all SELECT 5, 6 union all SELECT 2, 10 union all SELECT 3, 10 go select uid,sum(m