近期价格处于降价趋势(至少调了3次)的所有商品
2010-01-03 10:58
183 查看
--近期价格处于降价趋势(至少调了3次)的所有商品
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([日期] datetime,[商品编码] varchar(6),[价格] numeric(3,1))
insert [tb]
select '20091101','033001', 11.9 union all
select '20091101','033002', 30.5 union all
select '20091101','033003', 2 union all
select '20091102','033001', 11.9 union all
select '20091102','033002', 30 union all
select '20091102','033003', 2 union all
select '20091103','033001', 11.5 union all
select '20091103','033002', 30.5 union all
select '20091103','033003', 2.5 union all
select '20091104','033001', 11.5 union all
select '20091104','033002', 30.5 union all
select '20091104','033003', 2.5 union all
select '20091105','033001', 11.5 union all
select '20091105','033002', 30.5 union all
select '20091105','033003', 2.8 union all
select '20091106','033001', 11.5 union all
select '20091106','033002', 30 union all
select '20091106','033003', 2.9 union all
select '20091107','033001', 11 union all
select '20091107','033002', 30 union all
select '20091107','033003', 2.9 union all
select '20091108','033001', 10.8 union all
select '20091108','033002', 30 union all
select '20091108','033003', 2.9
--------------开始查询--------------------------
with cte2 as
(select row_number() over (partition by 商品编码 order by 价格 desc) as denserank,* from tb)
select * from cte2
where 商品编码 in (select 商品编码 from cte2 where 日期='20091108' and denserank>=3)
order by 商品编码,日期
/*
denserank 日期 商品编码 价格
----------------------------------
1 2009-11-01 033001 11.9
2 2009-11-02 033001 11.9
3 2009-11-03 033001 11.5
4 2009-11-04 033001 11.5
5 2009-11-05 033001 11.5
6 2009-11-06 033001 11.5
7 2009-11-07 033001 11.0
8 2009-11-08 033001 10.8
4 2009-11-01 033002 30.5
5 2009-11-02 033002 30.0
3 2009-11-03 033002 30.5
2 2009-11-04 033002 30.5
1 2009-11-05 033002 30.5
6 2009-11-06 033002 30.0
8 2009-11-07 033002 30.0
7 009-11-08 033002 30.0
*/
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([日期] datetime,[商品编码] varchar(6),[价格] numeric(3,1))
insert [tb]
select '20091101','033001', 11.9 union all
select '20091101','033002', 30.5 union all
select '20091101','033003', 2 union all
select '20091102','033001', 11.9 union all
select '20091102','033002', 30 union all
select '20091102','033003', 2 union all
select '20091103','033001', 11.5 union all
select '20091103','033002', 30.5 union all
select '20091103','033003', 2.5 union all
select '20091104','033001', 11.5 union all
select '20091104','033002', 30.5 union all
select '20091104','033003', 2.5 union all
select '20091105','033001', 11.5 union all
select '20091105','033002', 30.5 union all
select '20091105','033003', 2.8 union all
select '20091106','033001', 11.5 union all
select '20091106','033002', 30 union all
select '20091106','033003', 2.9 union all
select '20091107','033001', 11 union all
select '20091107','033002', 30 union all
select '20091107','033003', 2.9 union all
select '20091108','033001', 10.8 union all
select '20091108','033002', 30 union all
select '20091108','033003', 2.9
--------------开始查询--------------------------
with cte2 as
(select row_number() over (partition by 商品编码 order by 价格 desc) as denserank,* from tb)
select * from cte2
where 商品编码 in (select 商品编码 from cte2 where 日期='20091108' and denserank>=3)
order by 商品编码,日期
/*
denserank 日期 商品编码 价格
----------------------------------
1 2009-11-01 033001 11.9
2 2009-11-02 033001 11.9
3 2009-11-03 033001 11.5
4 2009-11-04 033001 11.5
5 2009-11-05 033001 11.5
6 2009-11-06 033001 11.5
7 2009-11-07 033001 11.0
8 2009-11-08 033001 10.8
4 2009-11-01 033002 30.5
5 2009-11-02 033002 30.0
3 2009-11-03 033002 30.5
2 2009-11-04 033002 30.5
1 2009-11-05 033002 30.5
6 2009-11-06 033002 30.0
8 2009-11-07 033002 30.0
7 009-11-08 033002 30.0
*/
相关文章推荐
- magento -- 修改所有商品的价格为原来的1.2倍示例
- 子查询2-查询所有价格大于平均价格的商品,并且按价格降序排序
- 【python】京东价格监控——自行设置商品,降价邮件提醒
- 购物券消费方案 公司发了某商店的购物券1000元,限定只能购买店中的m种商品。 每种商品的价格分别为m1,m2,…,要求程序列出所有的正好能消费完该购物券的不同购物方法。
- 所有商品价格水平涨幅明显 中国进入通胀时代
- 【转】oracle10g升级10.2.0.4补丁后,提示ORA-12526: TNS: 监听程序: 所有适用例程都处于受限模式问题处理
- java观察着observer模式---商品价格变动通知客户
- 利用nodejs+phantomjs+casperjs采集淘宝商品的价格
- js 对商品价格进行排序
- js模拟购物车商品价格的增减
- 实现判断商品折扣价格
- R语言rvest包爬取当当网单个商品的商品id,品牌,价格等商品属性
- 【程序1】看商品猜价格
- 电商如何对商品进行价格定位?(一)
- 16张图,揭秘16个商品的价格构成
- ECSHOP全站调用购物车显示商品图片,价格,数量,总价等详细信息
- 查询返回所有商品描述的前60位个字符,然后添加"..."
- dede首页调用商品价格
- 抓取淘宝天猫的商品的促销价格
- smarty单模板多缓存——解决缓存后所有商品页面都一样的问题