让人头疼的问题,,

feathersea 2004-03-26 05:05:08
要执行的操作如下,首先在一个表中的列选择出头n行,然后再在这n行中选择最大的,给它赋值,下面这么写好像不行,谁能给出一个替代的方法
set max(select top n from 表 where 列名=~~)=~~
...全文
27 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveSQL 2004-03-26
  • 打赏
  • 举报
回复
假定id是你表的主键
exec('update b set b.fieldname='+@你的变量值
+' from yourtable b,
(
select id,max(fieldname) fieldname
from (select top '+@n+' id,filedname from yourtable )a group by id
)a
where a.id=b.id')
yuncai 2004-03-26
  • 打赏
  • 举报
回复
update 表 set 列名= XXX
WHERE 字段=(select max(select top n from 表 where 列名=~~)from 表)
zjcxc 元老 2004-03-26
  • 打赏
  • 举报
回复
--忘记给变量了
declare @变量 int

select @变量=max(字段) from (select top n from 表 where ...)a
victorycyz 2004-03-26
  • 打赏
  • 举报
回复

要给哪个对象赋值?
zjcxc 元老 2004-03-26
  • 打赏
  • 举报
回复
declare @变量 int

select max(字段) from (select top n from 表 where ...)a

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧