0

私のクエリは次のようになります。それがうまく実行されたとします.Where句の最後の部分を混乱させました.2つの異なるテーブルからそれを書くことができますか..どのように書くことができますか.その日付範囲からアクティブなスタッフを表示したい.

select d.Division,a.FirstName,
 (select count(h.id) from Department h
  inner join institution i on d.institution_id = i_Id
  ----
  ----
where i.institution_id =d.Id and h. date between @startDate and @endDate) as test

from Division d, inmate a
where d.Active = 1 and a.Active = 1

編集したクエリを編集しましたが、最終的には次のようになります..

select d.DivisionName,a.FirstName, (select count(h.id) from InHistory h inner join Institution i on h.Institution_id = i.Id inner join InType it on h.InType_id = it.Id inner join mate a on h.mate_id = a.Id where i.InstitutionRegion_id = d.Id and it.InTypeName like '%Staff%' and h.AdmissionDate between '18/02/2013' and '18/02/2013') as Admission from Division d, mate a where d.Active= 1 and a.Active =1 
4

2 に答える 2

0

SQLクエリからWHERE内に必要な数の句を追加できます。

例を見る

SELECT *
FROM employee inner join department on
    employee.DepartmentID = department.DepartmentID;
WHERE 
    employee.active = TRUE AND
    department.group = 3

http://en.wikipedia.org/wiki/Join_(SQL)#Inner_join

于 2013-02-25T04:41:34.457 に答える
0

はい、where 句内で有効な条件を指定していれば、where 句内の任意の数のテーブルを比較できます。SQL JOINSを参照する必要があると思います

于 2013-02-25T04:05:28.480 に答える