我有一個包含18000000行(TABLE_A)的表格。我必須每15分鐘執行一次存儲過程,以從TABLE_A中選擇數據,進行一些計算並將結果插入到另一個表(TABLE_B)中。 TABLE_A的這個值來自包含不同設備讀數的文件。因此,桌子會越來越大。創建包含上百萬行的表格的視圖
這是文件內容的示例:
'2015-10-01 11:00:00.000';'par01';1
'2015-10-01 12:00:00.000';'par02';1
'2015-10-01 12:00:00.000';'par03';1
我認爲這是更好地插入來自文件到另一個表(TABLE_C)的新值,並用該值進行計算TABLE_C。我想要一個查詢,當某個變量達到一個月的數據時,將大於一個月的行插入TABLE_A(對於我來說,一個月就足以進行計算)。因此,在TABLE_C中只有一個月的數據,計算的執行速度將比使用18000000行的速度更快。
這是表中的一個簡單的例子:
DECLARE @TABLE_C(timestamp datetime, parameter char(5), value int)
DECLARE @TABLE_A(timestamp datetime, parameter char(5), value int)
INSERT @TABLE_C values
('2015-10-01 11:00:00.000','par01',1),
('2015-10-01 12:00:00.000','par01',1),
('2015-09-01 11:03:00.000','par01',2),
('2015-09-01 12:03:00.000','par01',2),
('2015-08-01 11:06:00.000','par01',3),
('2015-08-01 12:06:00.000','par01',3),
('2015-09-01 11:00:00.000','par02',1),
('2015-09-01 12:00:00.000','par02',1),
('2015-08-01 11:03:00.000','par02',2),
('2015-08-01 12:03:00.000','par02',2),
('2015-07-01 11:06:00.000','par02',3),
('2015-07-01 12:06:00.000','par02',3),
('2015-10-01 11:00:00.000','par03',1),
('2015-10-01 12:00:00.000','par03',1),
('2015-09-01 11:03:00.000','par03',2),
('2015-09-01 12:03:00.000','par03',2),
('2015-08-01 11:06:00.000','par03',3),
('2015-08-01 12:06:00.000','par03',3)
結果必須是財產以後像它:
INSERT @TABLE_C values
('2015-10-01 11:00:00.000','par01',1),
('2015-10-01 12:00:00.000','par01',1),
('2015-09-01 11:00:00.000','par02',1),
('2015-09-01 12:00:00.000','par02',1),
('2015-10-01 11:00:00.000','par03',1),
('2015-10-01 12:00:00.000','par03',1)
INSERT @TABLE_A values
('2015-09-01 11:03:00.000','par01',2),
('2015-09-01 12:03:00.000','par01',2),
('2015-08-01 11:06:00.000','par01',3),
('2015-08-01 12:06:00.000','par01',3),
('2015-08-01 11:03:00.000','par02',2),
('2015-08-01 12:03:00.000','par02',2),
('2015-07-01 11:06:00.000','par02',3),
('2015-07-01 12:06:00.000','par02',3),
('2015-09-01 11:03:00.000','par03',2),
('2015-09-01 12:03:00.000','par03',2),
('2015-08-01 11:06:00.000','par03',3),
('2015-08-01 12:06:00.000','par03',3)
張貼這使得沒有任何意義。你想做什麼?視圖中不能有循環或參數。這將是一個開始的好地方。 http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/ –
我在這個問題上做了一些改變。你明白我的問題嗎? – JosepB
不可以。你的問題根本沒有任何意義。結果的邏輯是什麼?數據來自哪裏? http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx –