2

ここでクエリのレイアウトを変更して、検索時間を 1 つの列にまとめて表示し、Web サイトでの検索を順番に表示できるようにしようとしています。

どんな助けでも大歓迎です。

ここに画像の説明を入力

コード:

Select 
StVS.ID AS 'SessionID',

-- Search Details
StBe.Bedrooms AS 'Searches Bedrooms',
StDo.Dogs AS 'Searches Dogs',
StDu.Duration AS 'Searches Duration',

-- Search times
StBe.datetimeselected AS 'Bedrooms time',
StDo.datetimeselected AS 'Dogs time',
StDu.datetimeselected AS 'Duration time'

FROM Stats_VisitorSessions StVs

-- Searches
left join Stats_Bedrooms StBe on StBe.SessionID=StVS.SessionID
left join Stats_Dogs StDo on StDo.SessionID=StVS.SessionID
left join Stats_Duration StDu on StDu.SessionID=StVS.SessionID
4

2 に答える 2

1

ユニオンを使用:

Select 
StVS.ID AS 'SessionID',

StBe.datetimeselected AS 'SearchTime',
StBe.Bedrooms AS Bedrooms,
NULL as Dogs,
NULL as Duration 

FROM Stats_VisitorSessions StVs

left join Stats_Bedrooms StBe on StBe.SessionID=StVS.SessionID
UNION ALL
Select 
StVS.ID AS 'SessionID',

StDo.datetimeselected AS 'SearchTime',
NULL AS Bedrooms,
StDo.Dogs as Dogs,
NULL as Duration 

FROM Stats_VisitorSessions StVs

left join Stats_Dogs StDo on StDo.SessionID=StVS.SessionID

UNION ALL
Select 
StVS.ID AS 'SessionID',

StDu.datetimeselected AS 'SearchTime',
NULL AS Bedrooms,
NULL as Dogs,
StDu.Duration as Duration 

FROM Stats_VisitorSessions StVs

left join Stats_Duration StDu on StDu.SessionID=StVS.SessionID
于 2013-11-12T11:35:17.380 に答える
0
SELECT t.SessionID, t1./dog-rel info/, t1./bedroom-rel info/, t1./dur-rel info/ FROM Table t
INNER JOIN (
    SELECT SessionID, /dog related into/ and nulls for other info
    UNION ALL
    SELECT SessionID, nulls for dog,  /bedrom related into/, nulls for duration
    UNION ALL
    SELECT SessionID, nulls for all above, /duration related into/ 
) t1 ON (t.SessionId = t1.SessionId)

3つの左外部結合でも作成できます

SELECT t.SessionID, t1./dogs rel info/, t2./bedroom rel info/, t3./duration rel info/ FROM Table t
LEFT OUTER JOIN Table as t1 ON (t.SessionId = t1.SessionId)
LEFT OUTER JOIN Table as t2 ON (t.SessionId = t2.SessionId)
LEFT OUTER JOIN Table as t3 ON (t.SessionId = t3.SessionId)
于 2013-11-12T11:31:07.177 に答える