SELECT * FROM `people` WHERE first_name like 'm%' and last_name like 'm%';
- 这会选择具有相同名字和姓氏的人,但仅此m
而已。如何从 a 到 z 选择所有这样的人(按 desc 排序不是问题)?
SELECT * FROM `people` WHERE UPPER(LEFT(first_name, 1)) = UPPER(LEFT(last_name, 1))
说明:取名字和姓氏最左边的 1 个字符,将它们转换为大写,并进行比较。
SELECT * FROM people WHERE LEFT(first_name, 1) = LEFT(last_name, 1);
ORDER BY last_name, first_name
select *
from people
where substring(first_name,1,1) = substring(last_name,1,1)
order by last_name, first_name