52. 获取Employees中的first

xiaoxiao2025-05-30  22

题目描述

获取Employees中的first_name,查询按照first_name最后两个字母,按照升序进行排列 CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); 输出格式:

first_nameChirstianTzvetanBezalelDuangkaewGeorgiKyoichiAnnekeSumantMaryPartoSaniya

 

select first_name from employees order by substr(first_name, -2);

或者

select first_name from employees order by substr(first_name, length(first_name) - 1);

substr(X,Y) 函数,X是要截取的字符串,Y是截取开始的位置,第一个字符串的位置是1,不是0,如果Y等于length(X),则截取出最后一个字符。

转载请注明原文地址: https://www.6miu.com/read-5030973.html

最新回复(0)