请教SQL语句,查询每月数据,但其中有几个月的没有,要取前月的数据。

glvicky glvicky 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
ID Number Price Year Month
1 1 123.00 2013 2
2 1 182.00 2013 1
3 1 141.00 2012 12
4 1 162.00 2012 7
5 1 160.00 2012 1

数据格式如上,要查询Number为1的产品的最近1年的价格,如果某月为空,则取前面有价格的月份,如查询时间2013年1月,编号为1的产品最一年的价格结果应为如下:
Number Pirce Year Month
1 182.00 2013 1
1 141.00 2012 12
1 162.00 2012 11
1 162.00 2012 10
1 162.00 2012 9
1 162.00 2012 8
1 162.00 2012 7
1 160.00 2012 6
...
1 160.00 2012 2

请问存储过程应该如何实现?
...全文

相关推荐

数据库sql语句按时间查询全部详解

数据库sql语句按时间查询全部详解 datediff(day,列名,getdate())等函数的使用例子

cup_student

SQL语句技巧:按月统计数据

表结构如下: qty date ———————————————- 13 2005/01/17 15 2005/01/19 3 2005/01/25 105 2005/01/27 1 2005/01/31 352 2005/02/03 12 2005/02/04 255 2005/02/07 6 2005/02/18 1 2005/02/19 28 2005/02/21 1 2005/02/22 394 2005/02/23 359 2005/02/24 313 2005/02/25 325 2005/02/26 544 2005/02/27 68 2005/02/28 2 2005/03/01

weixin_38521169

SQL语句,查询当月,当年数据

当月数据 select * from table t where t.create_time >=TRUNC(SYSDATE, 'MM') and t.create_time=trunc(sysdate,'YYYY') and t.create_time=trunc(sysdate,'day')+1 and t.create_time=trunc(next_day(sysdate-8,1)+1) and t.create_time<=trunc(next_day(sysdate-8,1)+7) select trunc(next_day(sysdate - 8, 1) + 1) as 周一, trunc(next_day(sysdate - 8, 1) + 2) as 周二, trunc(next_day(sysdate - 8, 1) + 3) as 周三, trunc(next_day(sysdate - 8, 1) + 4) as 周四, trunc(next_day(sysdate - 8, 1) + 5) as 周五, trunc(next_day(sysdate - 8, 1) + 6) as 周六, trunc(next_day(sysdate - 8, 1) + 7) as 周日 from dual;

dengf1984

数据库SQL查询语句练习题.doc

结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统; sql 语句就是对数据库进行操作的一种语言。 常见语句 更新:update table1 set field1=value1 where 范围 查找:select * from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串) 排序:select * from table1 order by field1,field2 [desc] 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:select min(field1) as minvalue from table1[separator]

皆非ay

SQL2000 统计每周,每月,每季,每年的数据

实例介绍按照每周,每月,每季,每年如何统计数据

haohao_kobe
评论 2
收藏 已收藏
分享
返回顶部
glvicky
MS-SQL Server 34,876 成员 254,635 内容