1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| mysql> desc t;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| c1 | int(11) | YES | | NULL | |
| c2 | int(11) | YES | | NULL | |
| c3 | int(11) | YES | | NULL | |
| c4 | int(11) | YES | | NULL | |
| c5 | int(11) | YES | | NULL | |
| c6 | int(11) | YES | | NULL | |
| c7 | int(11) | YES | | NULL | |
| c8 | int(11) | YES | | NULL | |
| c9 | int(11) | YES | | NULL | |
| c10 | int(11) | YES | | NULL | |
| c11 | int(11) | YES | | NULL | |
| c12 | int(11) | YES | | NULL | |
| c13 | int(11) | YES | | NULL | |
| c14 | int(11) | YES | | NULL | |
| c15 | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
15 rows in set (0.00 sec)
mysql> select column_name, ordinal_position
-> from information_schema.columns
-> where table_name = 't'
-> order by ordinal_position;
+-------------+------------------+
| column_name | ordinal_position |
+-------------+------------------+
| c1 | 1 |
| c2 | 2 |
| c3 | 3 |
| c4 | 4 |
| c5 | 5 |
| c6 | 6 |
| c7 | 7 |
| c8 | 8 |
| c9 | 9 |
| c10 | 10 |
| c11 | 11 |
| c12 | 12 |
| c13 | 13 |
| c14 | 14 |
| c15 | 15 |
+-------------+------------------+
15 rows in set (0.01 sec)
mysql> select group_concat(column_name order by ordinal_position separator ',')
-> from information_schema.columns
-> where table_name = 't';
+-------------------------------------------------------------------+
| group_concat(column_name order by ordinal_position separator ',') |
+-------------------------------------------------------------------+
| c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15 |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select group_concat(column_name order by ordinal_position separator ',')
-> from information_schema.columns
-> where table_name = 't'
-> and ordinal_position between 5 and 10;
+-------------------------------------------------------------------+
| group_concat(column_name order by ordinal_position separator ',') |
+-------------------------------------------------------------------+
| c5,c6,c7,c8,c9,c10 |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> |
Partager