0

私はこのクエリを持っています:

(SELECT e.IdEvent,e.EventName,e.EventSubtitle,e.EventDescription,l.LocationName,e.EventVenue,EventStartDate,e.EventEndDate,e.EventHost,c.CategoryName,l.LocationCity,l.LocationState,e.isTBA,
(SELECT s.status FROM jos_rsevents_subscriptions s WHERE s.IdUser = 72 AND s.IdEvent = e.IdEvent LIMIT 1) as status 
FROM jos_rsevents_events e 
    LEFT JOIN jos_rsevents_locations l ON e.IdLocation=l.IdLocation 
    LEFT JOIN jos_rsevents_categories c ON e.IdCategory=c.IdCategory 
WHERE 1=1  AND status < 3 ) ORDER BY  EventStartDate

しかし、私はエラーが発生します。「'where 句' の列 'status' が不明です

どうすればこれを修正できますか?

4

2 に答える 2

2

HAVING代わりに使用してみてください。これは、サブクエリの実行後に適用されます。例:

(SELECT e.IdEvent,e.EventName,e.EventSubtitle,e.EventDescription,l.LocationName,e.EventVenue,EventStartDate,e.EventEndDate,e.EventHost,c.CategoryName,l.LocationCity,l.LocationState,e.isTBA,
(SELECT s.status FROM jos_rsevents_subscriptions s WHERE s.IdUser = 72 AND s.IdEvent = e.IdEvent LIMIT 1) as status 
FROM jos_rsevents_events e 
    LEFT JOIN jos_rsevents_locations l ON e.IdLocation=l.IdLocation 
    LEFT JOIN jos_rsevents_categories c ON e.IdCategory=c.IdCategory 
HAVING status < 3 ) ORDER BY  EventStartDate
于 2009-09-11T13:47:53.060 に答える
0

テーブルjos_rsevents_subscriptionsに主キーがある場合は、次のようにすることもできます。

 SELECT e.IdEvent, e.EventName, e.EventSubtitle, e.EventDescription, 
     l.LocationName, e.EventVenue, EventStartDate, e.EventEndDate, 
     e.EventHost, c.CategoryName, l.LocationCity, l.LocationState, e.isTBA, 
     s.status     
 FROM jos_rsevents_events e     
    LEFT JOIN jos_rsevents_locations l 
       ON e.IdLocation=l.IdLocation     
    LEFT JOIN jos_rsevents_categories c 
       ON e.IdCategory=c.IdCategory 
    Left Join jos_rsevents_subscriptions s 
       On s.PK = (Select Max(PK) From jos_rsevents_subscriptions
                  Where IdUser = 72 
                     AND IdEvent = e.IdEvent)
 WHERE 1=1 AND status < 3  
 ORDER BY EventStartDate

PSなぜ1=1 ??

于 2009-09-11T14:07:28.373 に答える