日期:2014-05-18 浏览次数:20460 次
select 购买客户ID from 销售表 group by 购买客户ID having sum(销售金额)>10000
------解决方案--------------------
declare @T table (产品名称 int,销售数量 int,销售金额 int,购买客户ID int) insert into @T select 1,111,200,1 union all select 2,444,10,2 union all select 3,603,10,3 union all select 4,444,10,3 union all select 5,44,100,4 select 购买客户id from @t group by 购买客户id having(sum(销售金额*销售数量)>10000) /* 购买客户ID ----------- 1 3 */
------解决方案--------------------
select 购买客户IDfrom 销售表group by 购买客户ID having sum(销售金额)>10000
------解决方案--------------------
select * from 销售表 group by 购买客户ID having sum(销售金额)>10000
------解决方案--------------------
这是orcale的吧?
select 购买客户id from 销售表 group by 购买客户id having(sum(销售金额*销售数量)>10000)
------解决方案--------------------
create table t1(产品名称 varchar(10), 销售数量 int, 销售金额 float, 购买客户ID varchar(10)) insert t1 select 'ghg',45,538.00,'001' union all select 'klk',10,856.00,'001' union all select 'ghg',85,52.00,'002' go select 购买客户ID as VIP客户 into vip from ( select 购买客户ID from t1 group by 购买客户ID having sum(销售数量*销售金额)>10000 ) as a go select * from vip /* VIP客户 ----- 001 */ go drop table t1,vip
------解决方案--------------------
select 购买客户ID
from 销售表
group by 购买客户ID
having sum(销售金额)>10000
得到的这个购买客户ID肯定是你客户表没有的啊,直接插入不久好了吗
------解决方案--------------------
先求出满足VIP要求的客户ID:
select 购买客户ID as cid into #t
from 销售表
group by 购买客户ID
having sum(销售金额)>10000
--删除重复客户ID
delete from #t a,VIP客户表 b where a.cid=b.客户ID
--插入到VIP客户表
insert into VIP客户表(客户ID) select sid from #t
--删除临时表#t
drop table #t