SELECT * FROM `people` WHERE first_name like 'm%' and last_name like 'm%';
- 这会选择具有相同名字和姓氏的人,但仅适用于m
。如何从a到z选择所有这样的人(按desc命令不是问题)?
答案 0 :(得分:5)
SELECT * FROM `people` WHERE UPPER(LEFT(first_name, 1)) = UPPER(LEFT(last_name, 1))
说明:获取名字和姓氏最左边的1个字符,将它们转换为大写,然后比较它们。
答案 1 :(得分:3)
SELECT * FROM people WHERE LEFT(first_name, 1) = LEFT(last_name, 1);
ORDER BY last_name, first_name
答案 2 :(得分:2)
select *
from people
where substring(first_name,1,1) = substring(last_name,1,1)
order by last_name, first_name