NutzCN Logo
问答 带有mysql局部变量的sql语句中的@如何保留
发布于 2955天前 作者 qq_2b7489e3 1423 次浏览 复制 上一个帖子 下一个帖子
标签:

select result.* from (
select theme.*,@rownum:=@rownum+1,
if(@forum_id=theme.forum_id,@sort:=@sort+1,@sort:=1) as sort,
@forum_id = theme.forum_id from
(select * from bbs_theme where state = 0 and forum_id in
('2532cc83242d41f18c86595c053792e7') order by
forum_id DESC,top_num DESC,is_essence desc, replies DESC) theme,
(select @rownum:=0,@forum_id:=null,@sort:=0 ) a
) result where result.sort < 5

会被替换成
select result.* from (select theme.*,:=+1,if(=theme.forum_id,:=+1,:=1) as sort,
= theme.forum_id from (select * from bbs_theme where state = 0 and
forum_id in ('2532cc83242d41f18c86595c053792e7') order by forum_id DESC,t
op_num DESC,is_essence desc, replies DESC) theme,(select :=0,:=null,:=0 ) a) result where result.sort < 5

我想保留开始的语句中的@rownum,@forum_id,@sort 等应该如何处理

4 回复

用 @@forum_id

自定义SQL的转义问题???

http://nutzam.com/core/dao/customized_sql.html

输入 "@@" 表示一个 '@'
输入 "$$$$" 表示一个 '$'

@wendal 好的知道了谢谢

@Rekoe 好的知道了谢谢

添加回复
请先登陆
回到顶部