私は、私が興味を持っています。戻るSQLデータは
1列が日付で、2つのカラムを持つテーブルを持って、もう一方はタグ名です。
同じ日付に一致する別の列にタグ名を戻したいと思います。
サブクエリを使用してこれを実現できますが、効率的な方法がありますか?私は約20-30k行を検索して約30万件の検索結果を得ようとしています。
日付を確実に並べるための最も効率的な方法は何ですか。
これは私の質問です。
はあなたがSELECT ah1.DateTime,ah1.Value as TPH,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM1_NXG.NXG_I'
and datetime = ah1.DateTime
) as EM1_Current,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM2_NXG.NXG_I'
and datetime = ah1.DateTime
) as EM2_Current,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM1_NXG.NXG_SPEED'
and datetime = ah1.DateTime
) as EM1_Speed,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM2_NXG.NXG_SPEED'
and datetime = ah1.DateTime
) as EM2_Speed,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM1_NXG.NXG_P'
and datetime = ah1.DateTime
) as EM1_Power,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM2_NXG.NXG_P'
and datetime = ah1.DateTime
) as EM2_Power,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM1_NXG.NXG_TRQ'
and datetime = ah1.DateTime
) as EM1_Torque,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM2_NXG.NXG_TRQ'
and datetime = ah1.DateTime
) as EM2_Torque,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM1_NXG.NXG_TRQ_UTIL'
and datetime = ah1.DateTime
) as EM1_Torque_U,
(select value
from dbo.AnalogHistory
where tagname = 'LS_EM2_NXG.NXG_TRQ_UTIL'
and datetime = ah1.DateTime
) as EM2_Torque_U,
(select value
from dbo.AnalogHistory
where tagname = 'LS_TE754001G.PVAI'
and datetime = ah1.DateTime
) as EM1_NDE,
(select value
from dbo.AnalogHistory
where tagname = 'LS_TE754001H.PVAI'
and datetime = ah1.DateTime
) as EM1_DE
FROM [Runtime].[dbo].[AnalogHistory] ah1
where TagName = 'CR_WQI752010.PVAI'
and wwResolution = '600000'
and DateTime > '20160816'
and wwRetrievalMode = 'cyclic'