mysql> select @host:=host from mysql.user where host!='localhost';
+----------------+
| @host:=host |
+----------------+
| 127.0.0.1 | --> set @host:='127.0.0.1';
| ::1 | --> set @host:='::1';
| wonhigh-test16 | --> set @host:='wonhigh-test16';
+----------------+
mysql> select @host; ---查询时只会取最后一行....不会是自己想的3行都显示;
+---------------+
| @host |
+----------------+
| wonhigh-test16 |
+----------------+
mysql>
mysql> select host,@rownum:=@rownum+1 AS rownum from mysql.user,(SELECT @rownum:=0) r where host!='localhost';
+-----------------+--------------+
| host | rownum |
+-----------------+--------------+
| 127.0.0.1 | 1 |
| ::1 | 2 |
| wonhigh-test16 | 3 |
+------------------+---------
-
--+
mysql>
set @rownum:=0;
select host,@rownum:=@rownum+1 AS rownum from mysql.user where host!='localhost';
mysql>select @host:=
GROUP_CONCAT
(host) host1 from mysql.user where host!='localhost';
+---------------------------------+
| host1 |
+--------------------------------+
| 127.0.0.1,::1,wonhigh-test16 |
+---------------------------------+
mysql>
mysql> SELECT substring_index(substring_index(a.host1, ',', b.id),',' ,-1 ) as
host1_
,b.id
FROM (select @host:=GROUP_CONCAT(host) host1 from mysql.user where host!='localhost') a
JOIN (select 1 id union all select 2 union all select 3) b
ON b.id<= (length(a.host1) - length(REPLACE(a.host1, ',', '')) + 1) order by b.id;
+-------------------+---------------+
| host1_ | id |
+------------------+-----------------+
| 127.0.0.1 | 1 |
| ::1 | 2 |
| wonhigh-test16 | 3 |
+-----------------+----------------+
mysql>
广播电视节目制作经营许可证(京) 字第1234号 中国互联网协会会员