mysql简单实现查询结果添加序列号的方法

方法1:

SELECT
    @rownum :=@rownum + 1 AS rownum,
    t.*
FROM
    integral_system_user t,
    (SELECT @rownum := 0) AS R;

 例子:

SELECT
	@ROWNUM :=@ROWNUM + 1 AS "ID",
	TB.*
FROM
	(
		SELECT
			c.`name` AS "编队名称",
			c.id AS "编队ID",
			b.user_id AS "用户ID",
			d.user_name AS "用户名称",
			b.del_flag AS "编队删除标志",
			(
				CASE
				WHEN b.del_flag = '0' THEN
					"未删除"
				ELSE
					"已删除"
				END
			) AS "编队是否删除",
			(
				CASE
				WHEN d.del_flag = '0' THEN
					"未删除"
				ELSE
					"已删除"
				END
			) AS "个人是否删除"
		FROM
			middle_user_team AS b,
			integral_system_team AS c,
			integral_system_user AS d
		WHERE
			b.team_id = c.id
		AND b.user_id = d.id
		AND b.team_id IN (
			'8a99cbc4626f3dde016270c860b200d2',
			'8a99cbc4626f3dde016270c8608e00d0'
		)
		ORDER BY
			c.id,
			b.del_flag
	) AS TB,
	(SELECT @ROWNUM := 0) R

 

posted on 2018-03-30 17:07  不丶懂  阅读(2329)  评论(0编辑  收藏  举报

导航