试图找出一个人的年龄小于其他人的查询

时间:2015-09-17 04:11:43

标签: mysql

道歉。我明天接受采访,完全吓坏了。

通过一些sql问题......

Table name :person 
ID int
Name char
Age int

print all the pairs of names where first person  age is less than second age (ordered by first person id)

Line contains two separated names (name of first and second person) order by first and then by second person id

2 个答案:

答案 0 :(得分:1)

SELECT p1.name, p2.name
FROM person p1, person p2
WHERE p1.age < p2.age
ORDER BY p1.id, p2.id

答案 1 :(得分:-1)

希望这会有所帮助

SELECT *
FROM person
WHERE age =  ( SELECT MIN(age) FROM person )