我在存储过程中有这个查询:
SELECT DISTINCT
a.UserProfileId,
a.FromProfileId,
mm.FromProfileId as ToProfileID
FROM ( SELECT
mup.UserProfileId,
mmb.FromProfileId
FROM dbo.Mindcracker_MailBox mmb
LEFT JOIN Mindcracker_UserProfile mup
ON mmb.ToProfileId=mup.UserProfileId
WHERE mup.UserProfileId=1144 ) a
LEFT JOIN dbo.Mindcracker_MailBox mm
ON a.FromProfileId=mm.ToProfileId
上述查询产生以下结果:
UserProfielId FromProfileID ToProfielID
1144 1152 1144
1144 1152 1378
1144 1152 1483
1144 1333 1143
1144 1333 1148
1144 1333 1290
1144 1333 1297
1144 1333 1333
1144 1333 1378
1144 1378 1143
1144 1378 1185
1144 1378 1333
1144 1378 1378
1144 1483 1143
1144 1483 1144
1144 1483 1297
1144 1483 1483
1144 11526 1148
1144 11526 1290
1144 11526 1333
1144 11526 1378
1144 11526 11526
我只想获得基于 FromProfileId 列的最高值,我的输出应该是这样的:
1144 1152 1144
1144 1333 1143
1144 1378 1143
1144 1483 1143