本文主要向大家介绍了MySQL数据库之在mysql中给查询的结果添加序号列 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。
一:第一种:
select (@i:=@i+1) as i,table_name.* from table_name,(select @i:=0) as it
例如:
(1)简单实例:select (@i:=@i+1) i,user_id from spcp_user_20170803 ,(select @i:=0) as it ORDER BY t.user_id desc;
技术分享
(2)复杂实例:
SELECT
(@i:=@i+1) as i,hs_cd,hs_owner_persons,hs_owner_certy_num,hs_full_addr,t5.value_name as hs_type,t6.value_name as hs_owner_type,hs_use_size,hs_build_size,t2.cj_num,t2.db_num,t2.high_age_num,t2.ls_person_num,t7.value_name as person_type,t4.org_name
FROM
house_info_20170803 t1,house_person_info_20170803 t2,person_info_20170803 t3,cmp_org t4,cfg_value t5,cfg_value t6,cfg_value t7,(select @i:=0) as it
WHERE
t1.hs_owner_certy_nu