with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)
with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)
with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)
#3
谢谢老师
,我体会下,一时间有点没看懂。
#4
with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)
with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)
with cte_1
as
(select A.logday,A.sale_amt,B.brand_name
from 销售表 A
join 商品基础信息表 B on A.SKU_ID=B.SKU_ID
where user_name='小明' and YEAR(logday)='2017'),
cte_2
as
(select A.logday,B.sale_amt,B.brand_name,
COUNT(*) over (partition by A.logday) AS qty,
1.5*lag(sale_amt,1,0) over (partition by A.logday order by B.logday) as last_amt
from cte_1 A
join cte_1 B on A.brand_name=B.brand_name and B.logday between A.logday and DATEADD(DAY,3,A.logday))
select * from cte_2 A
where qty=4
and not exists (select 1 from cte_2 where A.logday=logday and A.brand_name=brand_name and sale_amt<last_amt)