0

現在、25 歳以上であることを理由に登録システムで除外されている 25 歳から 29 歳までの学生の数を調べる必要があります。

テーブルは次のとおりですSTUDENTSTUDENT_STATUS_HISTORY

Student他のフィールドの中でPERSON_ID&を含みます。含む(4 を除く)BIRTH_DATE
Student_Status_HistoryREASON_CODE

私の質問は、テーブルを結合するための構文と、生年月日を使用して必要な年齢範囲を正しく計算する方法に関するものです。

誰でもアドバイスできますか?

4

2 に答える 2

3

PERSON_ID でテーブルを結合します。

生年月日を取得するには、日付差のような関数を使用します。

select  trunc((months_between(sysdate, dob))/12) age 
于 2013-01-23T11:55:20.047 に答える
1

このクエリを試してください:

select count(*) from student s join student_status_history ssh 
on 
   s.id=ssh.student_id
where 
  ss.reason_code=4 
and 
  DATEDIFF(year,s.birthdate,sysdate)>=25 and DATEDIFF(year,s.birthdate,sysdate)<=29

DateDIFFを参照してください。

編集DATEDIFF が DB でサポートされていない場合は、以下を試してください。

select count(*) 
from 
  student s 
join 
  student_status_history ssh 
on 
   s.id=ssh.student_id
where 
  ss.reason_code=4 
and 
  floor(months_between(s.birthdate, sysdate) /12)>=25 and
  floor(months_between(s.birthdate, sysdate) /12)<=29
于 2013-01-23T11:59:40.267 に答える