none
Column 'dbo.events.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. RRS feed

  • Question

  • Bonjour,

    j'ai une erreur sur SQL Server 2008; svp est ce que quelqu'un pourrait m'aider.. Merci

    ma requête:

    SELECT TOP 1000
     [dbo].events.id, 
     [dbo].events.category_id, 
     [dbo].events.location_id,
      [dbo].events.name, 
      [dbo].events.url,
      [dbo].events.description, 
       [dbo].events_categories.name as category_name, 
     [dbo].events_locations.name as location_name, 
    [dbo].calendar.event_date, [dbo].calendar.event_time, 
     MIN([dbo].calendar.event_time) as min_event_time, 
     COUNT([dbo].calendar.unique_key) as slots_count 
     FROM [dbo].calendar LEFT OUTER JOIN [dbo].events ON [dbo].calendar.event_id = [dbo].events.id 
       LEFT OUTER JOIN [dbo].events_categories ON [dbo].events.category_id = [dbo].events_categories.id
        LEFT OUTER JOIN [dbo].events_locations ON [dbo].events.location_id = [dbo].events_locations.id 
        WHERE 1=1 AND ([dbo].calendar.event_date >= '2013-08-01') AND ([dbo].calendar.event_date <= '2013-08-30') 
    GROUP BY [dbo].calendar.unique_key
    ORDER BY [dbo].calendar.event_date ASC

    • Modifié az.i lundi 3 août 2015 14:48
    lundi 3 août 2015 14:43

Toutes les réponses

  • IL faut faire : 

    SELECT TOP 1000
    [dbo].events.id, 
    [dbo].events.category_id, 
    [dbo].events.location_id,
    [dbo].events.name, 
    [dbo].events.url,
    [dbo].events.description, 
    [dbo].events_categories.name as category_name, 
    [dbo].events_locations.name as location_name, 
    [dbo].calendar.event_date, [dbo].calendar.event_time, 
    MIN([dbo].calendar.event_time) as min_event_time, 
    COUNT([dbo].calendar.unique_key) as slots_count 
    FROM [dbo].calendar LEFT OUTER JOIN [dbo].events ON [dbo].calendar.event_id = [dbo].events.id 
    LEFT OUTER JOIN [dbo].events_categories ON [dbo].events.category_id = [dbo].events_categories.id
    LEFT OUTER JOIN [dbo].events_locations ON [dbo].events.location_id = [dbo].events_locations.id 
    WHERE 1=1 AND ([dbo].calendar.event_date >= '2013-08-01') AND ([dbo].calendar.event_date <= '2013-08-30') 
    GROUP BY [dbo].events.id, [dbo].events.category_id, 
    [dbo].events.location_id,[dbo].events.name, 
    [dbo].events.url,[dbo].events.description, 
    [dbo].events_categories.name, [dbo].events_locations.name, 
    [dbo].calendar.event_date, [dbo].calendar.event_time, 
    ORDER BY [dbo].calendar.event_date ASC

    Il faut grouper sur les champs qui définisse, le calcul de : 

    MIN([dbo].calendar.event_time) as min_event_time, 
    COUNT([dbo].calendar.unique_key) as slots_count 

    C'est à dire les autres champs du select.

    lundi 3 août 2015 14:57