这详细的介绍了怎么使用自定义变量
set @rownum:=0;
select disease,rn,@rownum,@rownum:[email protected]+1 as cmt from disease_code
where @rownum <=1
结果:
disease rn @rownum cmt 002001 10 0 1 002003 11 1 2
总结: 本次查询中,首先执 where ,再执行 select
二、
set @rownum:=0;
select disease,rn,@rownum,@rownum:[email protected]+1 as cmt from disease_code
where @rownum <=1
order by rn
结果:
disease rn @rownum cmt 002001 10 0 1 002003 11 1 2 002002 12 2 3 002004 13 3 4 003001 20 4 5 003002 21 5 6 001001 30 6 7 001002 31 7 8 001003 32 8 9 004002 40 9 10 004003 41 10 11 004004 42 11 12 004001 43 12 13 012001 50 13 14 008001 60 14 15 010001 70 15 16 007001 80 16 17 011003 90 17 18 011001 91 18 19 011002 92 19 20 011004 93 20 21 006001 100 21 22 005001 110 22 23 005002 111 23 24 005003 112 24 25 009001 120 25 26 013001 130 26 27 014001 140 27 28 015001 150 28 29 016001 160 29 30
查询:
set @rownum:=0;
select disease,rn,@rownum,@rownum:[email protected]+1 as cmt from disease_code
where @rownum <=1
order by rn,@rownum
结果:
002001 10 0 1
002003 11 1 2
总结,第2个例子我现在也不明白,为什么,一个排序的差别,结果有这么大的区别。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/4492.html