首页 > 代码库 > MySLQ排序后标记排行
MySLQ排序后标记排行
查询排行及所有(表名.*)
1.
set @rownum=0; SELECT @rownum:=@rownum+1 AS top, customer.* FROM customer
2.
SELECT @rownum:=@rownum+1 AS top, customer.* FROM (SELECT @rownum:=0) r, customer ORDER BY customer.this_month_cost DESC
1和2的结果:
查询排行及id(表名.id)
SELECT @rownum:=@rownum+1 AS top, customer.id FROM (SELECT @rownum:=0) r, customer ORDER BY customer.this_month_cost DESC
结果:
排序后更新原表的排行:
UPDATE `customer` c, ( SELECT @rownum :=@rownum + 1 AS rownum, customer.id FROM (SELECT @rownum := 0) r, customer ORDER BY customer.this_month_cost DESC ) a SET c.top = a.rownum WHERE c.id = a.id
MySLQ排序后标记排行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。