2011-04-18 91 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