我的查詢看起來像這樣。假設它運行得很好.im混淆了的最後部分Where where clause.Can我可以從兩個不同的表中寫出來嗎?..我怎麼寫它,因爲我想顯示那些來自該日期範圍的Active的工作人員。查詢中的Where子句
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
是不是已經在做你想做的事了?它在兩個不同的表上測試條件。 – Patashu 2013-02-25 03:42:54
爲什麼你在子查詢中加入並使用這些連接進行外部查詢? – andho 2013-02-25 03:44:44
如果我沒有弄錯,是的,你可以 – c0dem0nkey 2013-02-25 03:46:44