如何配合 WHERE 子句使用 MySQL REVERSE() 函数来处理列数据?
MySQL REVERSE() 函数可以将列名称作为参数来颠倒其值。如果我们想应用某些条件,可以使用 WHERE 子句,如下所示
示例
mysql> Select Name, REVERSE(Name) from Student; +---------+---------------+ | Name | REVERSE(Name) | +---------+---------------+ | Aarav | varaA | | Gaurav | varuaG | | Gaurav | varuaG | | Harshit | tihsraH | | Yashraj | jarhsaY | +---------+---------------+ 5 rows in set (0.00 sec)
上面的查询颠倒了“Student”表的“Name”列中的值。现在,下面的查询将使用 REPLACE() 函数和 WHERE 子句
mysql> Select Name, REVERSE(Name) from Student WHERE Subject = 'History'; +-------+---------------+ | Name | REVERSE(Name) | +-------+---------------+ | Aarav | varaA | +-------+---------------+ 1 row in set (0.00 sec)
广告