表1
/T1582-1997工业产品业务
1
表2
/T1381-1997商业银行的发税标准
(1)(1)商业、金融、商业、金融、商业、商业、金融、商业、金融、商业等行业的产品
2
这是我的查询语句。
select * from table1
inner join table2
on table2.rollnumber = table1.rollnumber
where table1.Name <> table2.Name我的目标是将table1与表2的最高ID与rollnumber进行比较,在本例中,使用此查询的结果应该为none.你的帮助非常感谢..。
发布于 2015-04-04 21:09:26
尝试:
select * from table1 t1
cross apply ( select * from (select top 1 * from table2 t2 where t1.rn = t2.rn order by t2.id desc) t where t.name <> t1.name) c发布于 2015-04-04 21:28:48
你可以试试这个:
DECLARE @table1 TABLE (ID INT, RollNumber INT, Name VARCHAR(100))
DECLARE @table2 TABLE (ID INT, RollNumber INT, Name VARCHAR(100))
INSERT INTO @table1 VALUES(1,4,'John Doe')
INSERT INTO @table2
VALUES (1,4,'Jane Doe'),
(2,4,'John Doe');
SELECT A.RollNumber,
A.ID,
A.Name,
C.max_id
FROM @table1 A
CROSS APPLY (SELECT MAX(ID) FROM @table2 B WHERE A.RollNumber = B.RollNumber) C(max_id)
WHERE A.ID = C.max_id发布于 2015-04-04 21:44:41
Select * from table1 a
join (select max(Id) id, rollnumber,max(name) name from table2
group by rollnumber) t on t.id = a.id and t.rollnumber = a.rollnumber and t.name <> a.name;这是一个通用的解决方案,将在流行的数据库中工作。有时也比在性能上应用函数更好。
https://stackoverflow.com/questions/29451359
复制相似问题