概述
本来是在百度知道上看一个同学的提问。
http://zhidao.baidu.com/question/1541852359889277347.html
想了许久,发现可以用mysql的变量解决,
于是我给出了于下答案。
set @i := 0;
select concat(@i := @i + 1,’.’,title) as title
,type
from (SELECT ‘A’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘B’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘C’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘D’ title, 2 TYPE FROM DUAL UNION ALL
SELECT ‘E’ title, 2 TYPE FROM DUAL) a
where type=1
order by title asc;
set @i := 0;
select concat(@i := @i + 1,’.’,title) as title
,type
from (SELECT ‘A’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘B’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘C’ title, 1 TYPE FROM DUAL UNION ALL
SELECT ‘D’ title, 2 TYPE FROM DUAL UNION ALL
SELECT ‘E’ title, 2 TYPE FROM DUAL) a
where type=2
order by title asc;
还有个问题是如何将两个结果集合并为一,暂时还没发现,暂时搁置。
最后
以上就是野性爆米花为你收集整理的Mysql 给查询结果标序号的全部内容,希望文章能够帮你解决Mysql 给查询结果标序号所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复