由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - A question of filling in missing value in SQL
相关主题
SQL run a stored procedure by fetching from a cursor row by row猪一样的队友
Need help with an oracle SQL expression版上专家多,请教个MySQL的问题 (转载)
这“精妙sql语句”是错误的吗面试问题,关于oracle 8i
请问sql server里面怎么输出变量到文本文件?老印给我的一个Challenge
ask for help with a simple query!!!SQL问题请教: add one more column
2个table, 一个里面有4万个email, 一个里面有1万6千个email,如何比较?[转载] Hehe,不好意思,another question:)
请教SQL server的一个programming的问题,谢谢can I create a recordset with cursor?
一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)ORACLE error code 04031
相关话题的讨论汇总
话题: date话题: 098766话题: 2007话题: sql
进入Database版参与讨论
1 (共1页)
g****n
发帖数: 18
1
Hello,
I have a question on using SQL to fill in some missing values in a dataset?
Right now my dataset look like this
ID New_ID Date CV Value
3270001111111 098766 7/31/2007 check 40000
3270001111111 098766 9/30/2007 check 135000
3270001111111 098766 2/28/2008 check 75000
Note there is no date for 8/2007, 10/2007, 11/2007, 12/2007, and 1/2008. I
want to fill in those blanks with the data from previous month, making it
looks like the
B*****g
发帖数: 34098
2
ORACLE
WITH
DATA_TABLE AS
(SELECT 3270001111111 ID,'098766' NEWID,TO_DATE('07/31/2007', 'mm/dd/yyyy')
A_DATE,'check' CV,40000 A_VALUE FROM DUAL
UNION ALL
SELECT 3270001111111,'098766',TO_DATE('09/30/2007', 'mm/dd/yyyy'),'check',
135000 FROM DUAL
UNION ALL
SELECT 3270001111111,'098766',TO_DATE('02/28/2008', 'mm/dd/yyyy'),'check',
75000 FROM DUAL
UNION ALL
SELECT 3270001111112,'098757',TO_DATE('10/31/2007', 'mm/dd/yyyy'),'mo' ,
6000 FROM DUAL),
DATE_LIST AS
(SELECT TO_DATE('07/31/2007', 'mm/

【在 g****n 的大作中提到】
: Hello,
: I have a question on using SQL to fill in some missing values in a dataset?
: Right now my dataset look like this
: ID New_ID Date CV Value
: 3270001111111 098766 7/31/2007 check 40000
: 3270001111111 098766 9/30/2007 check 135000
: 3270001111111 098766 2/28/2008 check 75000
: Note there is no date for 8/2007, 10/2007, 11/2007, 12/2007, and 1/2008. I
: want to fill in those blanks with the data from previous month, making it
: looks like the

n********6
发帖数: 1511
3
/**************************
** MS SQL, USE CURSOR
** ADDDATE function need to be tested.
** Logic is not complete.
***************************/
DECLARE REC_cursor CURSOR STATIC FOR
SELECT id, newid, date, ...
FROM TABLE
OPEN REC_cursor
FETCH REC_cursor INTO @id, @newid, @date, ...
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF DATEADD(month, 1, @date) < '7/31/2007'
INSERT INTO TABLE
VALUES (@id, @newid, DATEADD(month, 1, @date), ...)
FETCH NEXT FROM REC_cursor INTO @id, @newid, @date,
1 (共1页)
进入Database版参与讨论
相关主题
ORACLE error code 04031ask for help with a simple query!!!
ORA-01002: fetch out of sequence问题2个table, 一个里面有4万个email, 一个里面有1万6千个email,如何比较?
SQL query 一问请教SQL server的一个programming的问题,谢谢
谁能帮我看看这个oracle function有什么错?一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)
SQL run a stored procedure by fetching from a cursor row by row猪一样的队友
Need help with an oracle SQL expression版上专家多,请教个MySQL的问题 (转载)
这“精妙sql语句”是错误的吗面试问题,关于oracle 8i
请问sql server里面怎么输出变量到文本文件?老印给我的一个Challenge
相关话题的讨论汇总
话题: date话题: 098766话题: 2007话题: sql