请大家帮我看看这个语句怎么写 persons:id name 1 小一 2 小二3 小三hetong:id ht_no1 141 151 162 17我要写一个语句,查询出每个人对应的最新的合同。最新是以ht_no来标识的,也就是最大值。结果应该是:id hetong1 162 17谢谢大家。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select a.id,b.hetongfrom persons aleft join (select id,max(ht_no) as ht_no from hetong group by id)b on a.id=b.id select persoms.id,T.ht_no from persomsjoin (select id,max(ht_no) as ht_no from hetong group by ID) Ton persoms.id=td.id select a.id,b.ht_no from persoms a join (select id,max(ht_no) ht_no from hetong group by id) b on a.id=b.id select id, ht_no as [hetong]from hetonggroup by id sorry!select id, max(ht_no) as [hetong]from hetonggroup by id 多个表关联查询的结果 做一列显示问题 如何得知表某个字段的创建时间 求救!!!关于批量添加问题 求sql语句 关于SQL SERVER2000占用内存的问题 查询语句如何获取小数点大于3位数的数字? 急,这个SQL该怎么写 SQL修改字段长度不改变数据类型varchar\nvarchar 一个动态行变列的问题 海量数据全文检索速度讨论 这条SQL语句该怎么写??? My Sql 子查询原理
from persons a
left join (select id,max(ht_no) as ht_no from hetong group by id)b on a.id=b.id
select persoms.id,T.ht_no from persoms
join (select id,max(ht_no) as ht_no from hetong group by ID) T
on persoms.id=td.id
select a.id,b.ht_no
from persoms a join (select id,max(ht_no) ht_no
from hetong
group by id) b on a.id=b.id
select id, ht_no as [hetong]
from hetong
group by id
from hetong
group by id