sql >> Database teknologi >  >> RDS >> Mysql

Dynamisk valg af kolonne i MySQL

Brug en forberedt erklæring:

mysql> SET @sql = CONCAT("SELECT ", (SELECT "NOW()"));
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @sql;
+--------------+
| @sql         |
+--------------+
| SELECT NOW() | 
+--------------+
1 row in set (0.00 sec)

mysql> PREPARE stmt FROM @sql;
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> EXECUTE stmt;
+---------------------+
| NOW()               |
+---------------------+
| 2009-04-06 23:08:31 | 
+---------------------+
1 row in set (0.00 sec)


  1. INSERT INTO mislykkes med node-mysql

  2. Sådan fungerer TIME_FORMAT() i MariaDB

  3. Sådan transponeres MYSQL db i PHP

  4. PostgreSQL matematiske funktioner