SQL语句获取MAX()的值后没怎么能获取这个值所对应的主键?
SELECTUSER_ID,MAX(MEMBER_NUMBER)FROMPM_MAN_HOUR_STANDARD如上SQL,如果直接这么写,得到的MEMBER_NUMBE...
SELECT
USER_ID,
MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
如上SQL,如果直接这么写,得到的MEMBER_NUMBER的最大值列与USER_ID不匹配.怎么能获取最大的MEMBER_NUMBER行的ID呢? 展开
USER_ID,
MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
如上SQL,如果直接这么写,得到的MEMBER_NUMBER的最大值列与USER_ID不匹配.怎么能获取最大的MEMBER_NUMBER行的ID呢? 展开
5个回答
展开全部
用嵌套查询吧
select user_id from PM_MAN_HOUR_STANDARD where MEMBER_NUMBER =(select MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
)
select user_id from PM_MAN_HOUR_STANDARD where MEMBER_NUMBER =(select MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-12-21
展开全部
你查的就是最大值 没有指定要查谁的 要么 where user_id=XX 要么 group by 实在不行 max里边写个子查询也行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT top 1
USER_ID,
MAX(MEMBER_NUMBER) MEMBER_NUMBER
FROM
PM_MAN_HOUR_STANDARD
group by USER_ID
order by MEMBER_NUMBER desc
USER_ID,
MAX(MEMBER_NUMBER) MEMBER_NUMBER
FROM
PM_MAN_HOUR_STANDARD
group by USER_ID
order by MEMBER_NUMBER desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT
USER_ID,
MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
group by USER_ID
USER_ID,
MAX(MEMBER_NUMBER)
FROM
PM_MAN_HOUR_STANDARD
group by USER_ID
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT A.USER_ID FROM PM_MAN_HOUR_STANDARD A WHERE A = (SELELCT MAX(MEMBER)NUMBER FROM PM_MAN_HOUR_STANDARD)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询