2
SELECT * FROM `people` WHERE first_name like 'm%' and last_name like 'm%';

- 这会选择具有相同名字和姓氏的人,但仅此m而已。如何从 a 到 z 选择所有这样的人(按 desc 排序不是问题)?

4

3 回答 3

5
SELECT * FROM `people` WHERE UPPER(LEFT(first_name, 1)) = UPPER(LEFT(last_name, 1))

说明:取名字和姓氏最左边的 1 个字符,将它们转换为大写,并进行比较。

于 2013-11-05T21:31:20.493 回答
3
SELECT * FROM people WHERE LEFT(first_name, 1) = LEFT(last_name, 1);
ORDER BY last_name, first_name
于 2013-11-05T21:30:30.113 回答
2
select *
 from people
 where substring(first_name,1,1) = substring(last_name,1,1)
 order by last_name, first_name
于 2013-11-05T21:30:29.803 回答