我想以一个顺序为表的列中的数据排序,即我有一个表人的年龄
age
12
14
13
14
45
12
45
23
12
23
12
我想将所有相似的年龄一个接一个地分组。如何做到这一点?我尝试使用 group by select age from person group by age.这对我不起作用。
SELECT age FROM Person ORDER BY age
尝试这个:
SELECT * FROM Person ORDER BY age
我以为你想加入表格,为了做到这一点,你有以下选择:
1) 具有不同/唯一的简单连接
select distinct person.name, age.age
from person, age
Where Person.Age = Age.Age
order by age.age
结果:
person_5 12
person_3 14
person_1 23
person_4 23
person_2 45
2)右外连接
Select Distinct Person.Name, Age.Age
from person right outer join age
on Person.Age = Age.Age
order by age.age
结果:
person_5 12
null 13
person_3 14
person_1 23
person_4 23
person_2 45
3) 左外连接
Select Distinct Person.Name, Age.Age
from person left outer join age
On Person.Age = Age.Age
order by age.age
结果:
person_5 12
person_3 14
person_1 23
person_4 23
person_2 45
源表:人员表(人员和年龄列):
person_1 23
person_2 45
person_3 14
person_4 23
person_5 12
年龄表(仅限年龄列):
12
14
13
14
45
12
45
23
12
23
12
在MySQL
中,您可以在GROUP BY
不聚合列的情况下使用,但在中oracle
则不能。尝试使用DISTINCT
它,它只会选择唯一值。
SELECT DISTINCT age
FROM Person
Order by age ASC