こんにちは、私は Oracle の世界から来ましたが、SQL Server の経験はあまりありません。このクエリの内部セクションが機能しない理由を誰か教えてもらえますか? さまざまなオプションを試しましたが、どれも機能していないようです:
select EventType, sum(Executed), sum(TriggeredScenarios), sum(OpenAlerts),sum(TotalAlerts)
from (
select id,
'myEvent' as [EventType],
TriggeredScenarios,
Executed,
TotalAlerts = (select sum(cnt) as [TotalCount]
-- it breaks from here
from (select count(*) as [cnt]
from [myAlert1] aa, [Alert] bb
where aa.EventType = EventType
and aa.EventId = id
and aa.AlertId = bb.id
and bb.DetectionAlertType = 'myAlert1'
-- until here
UNION
select count(*) as [cnt]
from [myAlert2] aa, [Alert] bb
where aa.EventType = EventType
and aa.EventId = id
and aa.AlertId = bb.id
and bb.DetectionAlertType = 'myAlert2'
) aa),
OpenAlerts = (select sum(cnt) as [TotalAlerts]
from ( select count(*) as [cnt]
from [Alert] aa, [myAlert1] bb
where aa.currentstateid not in (select intStateID
from _AlertStates
where strGroupName like (N'AlertsClosed%')
)
and bb.EventType = EventType
and bb.EventId = id
and bb.AlertId = aa.id
and aa.DetectionAlertType = 'myAlert1'
UNION
select count(*) as [cnt]
from [Alert] aa, [myAlert2] bb
where aa.currentstateid not in (select intStateID
from _AlertStates
where strGroupName like (N'AlertsClosed%')
)
and bb.EventType = EventType
and bb.EventId = id
and bb.AlertId = aa.id
and aa.DetectionAlertType = 'myAlert2'
) aa )
from [myEvent]
where [Timestamp] >= '11/26/2012'
AND [Timestamp] < '11/27/2012'
UNION
select id,
'myEvent2' as [EventType],
TriggeredScenarios,
Executed,
TotalAlerts = (select sum(cnt) as [TotalCount]
from (select count(*) as [cnt]
from [myAlert1] aa, [Alert] bb
where aa.EventType = EventType
and aa.EventId = id
and aa.AlertId = bb.id
and bb.DetectionAlertType = 'myAlert1'
UNION
select count(*) as [cnt]
from [myAlert2] aa, [Alert] bb
where aa.EventType = EventType
and aa.EventId = id
and aa.AlertId = bb.id
and bb.DetectionAlertType = 'myAlert2'
) aa),
OpenAlerts = (select sum(cnt) as [TotalAlerts]
from ( select count(*) as [cnt]
from [Alert] aa, [myAlert1] bb
where aa.currentstateid not in (select intStateID
from _AlertStates
where strGroupName like (N'AlertsClosed%')
)
and bb.EventType = EventType
and bb.EventId = id
and bb.AlertId = aa.id
and aa.DetectionAlertType = 'myAlert1'
UNION
select count(*) as [cnt]
from [Alert] aa, [myAlert2] bb
where aa.currentstateid not in (select intStateID
from _AlertStates
where strGroupName like (N'AlertsClosed%')
)
and bb.EventType = EventType
and bb.EventId = id
and bb.AlertId = aa.id
and aa.DetectionAlertType = 'myAlert2'
) aa )
from [myEvent2]
where [Timestamp] >= '11/26/2012'
AND [Timestamp] < '11/27/2012'
)
group by EventName
何か助けてください。