0

まず、あいまいな質問のタイトルをお詫びします。そこに何を書いたらよいかわかりません。お知らせください。更新します。

今ここに行きます..
私は3つ持っています

Table   : target
Columns : target_id , target_employee_id, target_location_id, target_location_name, target_scheduled_on, target_exec_end_time, target_damaged, target_damaged_text


Table   : employee  
Columns : employee_id, employee_manager_id

Table   : location
Columns : location_id, location_name

少し説明 -> マネージャーの役​​割は、従業員のターゲットを作成することです。つまり、新しいターゲットには場所の名前とスケジュールが設定されます。その後、従業員がその場所を訪問し、損傷があるかどうかを報告します。これは、同じ場所で月に複数回発生する可能性があります。

表示する必要があるもの -> 損傷のあるターゲットのリスト - 2 つの日付 (target_exec_end_time) の間で、同じ場所の複数のレコードがある場合は、最大の日付を持つものを表示します。

詳細説明 -> 同じ場所を持つターゲットの複数のエントリが存在する可能性がありますが、1 つのインスタンスのみを表示する必要があります。ターゲット テーブル イメージ

私は説明するために最善を尽くしました。前もって感謝します。

4

3 に答える 3

0
select t.target_location_name,case when t.target_damaged >0 
then t.target_damaged_text else 'Not Damaged' end target_damaged_text, 
max(t.target_exec_end_time) from target t
inner join employee e on t.target_employee_id=e.employee_id
inner join location l on t.target_location_id=l.location_id
where t.target_exec_end_time between 'DATE1' and 'DATE2'
group by t.target_id,t.target_damaged_text 
于 2012-12-30T12:25:42.243 に答える
0
SELECT MAX(target_exec_end_time), *
FROM target
WHERE target_damaged=1
    AND target_exec_end_time BETWEEN '2012-12-01' AND '2012-12-31'
GROUP BY target_location_id
于 2012-12-30T12:25:51.760 に答える
0

これはどう:

 select * from target join employee on target.target_employee_id = employee.employee_id
     join location on target.target_location_name = location.location_name
     where target_exec_end_time between <start_date> and <end_date>
        and target_exec_end_time = (select max(target_exec_end_time) from location loc2
        where loc2.location_name = target.location_name)
     group by target.location_name;

ただし、 where に両方のtarget_exec_end_time句があるかどうかはわかりません。多分あなたは最大値が欲しいですか?

于 2012-12-30T12:17:48.470 に答える