-1
select distinct 
    assignedTo, 
    alert_id, 
    insert_date_time, 
    alert_status_id, 
    alert_action_id, 
    alert_call_reason_id, 
    target_date  
from Case_Management.AlertDetail 

正常に動作します。

select distinct 
    assignedTo, 
    alert_id, 
    max(insert_date_time), 
    alert_status_id, 
    alert_action_id, 
    alert_call_reason_id, 
    target_date  
from Case_Management.AlertDetail 

エラー列'Case_Management.AlertDetail.assignedTo'は、集計関数またはGROUP BY句のいずれにも含まれていないため、選択リストでは無効です。

私は困惑しています。

4

3 に答える 3

5

エラーは非常に明確です。集計関数にない列をGROUP BY句に追加してください。

select 
    assignedTo, 
    alert_id, 
    max(insert_date_time), 
    alert_status_id, 
    alert_action_id, 
    alert_call_reason_id, 
    target_date  
from Case_Management.AlertDetail 
GROUP BY assignedTo, 
         alert_id,
         alert_status_id, 
         alert_action_id,
         alert_call_reason_id, 
         target_date;
于 2013-03-19T19:42:13.797 に答える
0

集計があるため、2番目のクエリでgroupby句が必要です。骨材は

max(insert_date_time)
于 2013-03-19T19:42:21.250 に答える
0

達成したいことを考えてください。いくつかのレコードを選択したいのですが、列の1つは通常のレコードの内容ではなく、すべての列の要約です。あなたはそれを混ぜることはできません。

これを実現するには、データをグループ化するか、副選択を使用する必要があります。

于 2013-03-19T19:44:08.990 に答える