sqlserver 关于sql查询的问题

我现在有100个编号num。需要再A表(结构字段有ID,编号num,status,datetime)里面 ,找出这100个编号 按时间排序,最后时间的status。不要一个一个循环去找。能否一次性找出来? 有没有大神指点一二。小弟在此感谢啦~

select status from A where num in(num1,num2,num3...num100) order by datetime desc limit 1; num1-100就是你要传入的100个编号的值,如果你的编号是另一个表里,那就双表做个关联查询,最后按时间倒序取第一条就是最后时间的status

select top 1 status from A where num in (num1,num2,num3...num100) order by datetime desc

各位哥哥姐姐,我在自定义查询里面做了一个查询相关数据的表,可以正常查询,但是我想查询的结果可以按照我的要求正常排序,应该怎么修改这段语句?另外问问,如果需要把txtkc,tXtPlu这2个表自定义为别名,又应该怎么修改?
select txtkc.depcode as '部门',
txtkc.plucode as '商品编码',tXtPlu.barcode as '商品条码',tXtPlu.pluname as '商品名称',
tXtPlu.hjprice as '进价',tXtPlu.price as '售价',
txtkc.kcdxcount as '代销库存数量',txtkc.kcjxcount as '经销库存数量',
txtkc.kclxcount as '联销库存数量'
from txtkc,tXtPlu
where txtkc.plucode=tXtPlu.plucode and
(kcjxcount+kcdxcount+kclxcount)<3

select top 1 status from A where num in (num1,num2,num3...num100) order by datetime desc 倒叙排列,然后只取第一条,但每一条都要过一次

Order by 升序还是降序 随你自己
然后top N ?

https://zhidao.baidu.com/question/379436262.html

如果num编号连续的话select top 1 status from A where num between num1 and num100 order by datetime desc
如果num编号不连续的话就用in了,in会全表扫描,很多时候用 exists 代替 in 是一个好的选择,如: select num from a where num in(select num from b) 用下面的语句替换: select num from a where num exists(select 1 from b where num=a.num)

SELECT * From (Select Row_Number() Over(Partition By "编号" order By "时间字段" Desc) As RowNumber,* From "表名A" WHERE "编号" IN (" + 多个编号 + ")) As ZkData Where ZkData.RowNumber = 1 ;

不懂的别来装大神。自己研究出来了。

select top 1 status from A order by datetime desc查询的是按时间排序最近一条记录的status,如果要查询最早时间的去掉desc,这样与记录数无关