2011-04-18 119 views
0

努力讓我的頭圍繞此。 我想轉換下面的SQL語句(從oracle轉換爲sql)返回所有,而不是單個記錄。sql在哪裏子查詢編號

select * 
from table_1 
where ID = @myid and MyMonth = (select max (MyMonth) from table2 where ID = @myid) 

正如我所說的,我想返回作爲@myid給定值的所有內容的摘要。

刪除此處的ID部分不返回任何內容。

感謝,

回答

4

試試這個:

select * 
from table_1 t1 
where t1.MyMonth = (select max (t2.MyMonth) from table2 t2 where t1.ID = t2.ID) 
+0

的感謝!有一個金髮的時刻。 – nologo 2011-04-18 10:57:42

+0

也金髮.... – Markive 2015-10-14 06:55:19