テーブルの列のデータを1つの順序で注文したいのですが、テーブルを持っている人は次のような年齢です
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テーブル(personおよびage列):
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