生成以下两个结果集:
1).查询OCCUPATIONS中所有姓名的按字母顺序排列的列表,紧接着是每个职业的第一个字母作为括号(即:括在括号中).例如:AnActorName(A),ADoctorName(D),AProfessorName(P)和ASingerName(S).
2).查询OCCUPATIONS中每个职业的发生次数.按升序对事件进行排序,并按以下格式输出:
共有[occup_count] [职业] s.
表名:职业
总列数:两个=’名称’和’职业’,演示表如下所示:
样本输出:
Ashely(P)
Christeen(P)
Jane(A)
Jenny(D)
Julia(A)
Ketty(P)
Maria(A)
Meera(S)
Priya(S)
Samantha(D)
There are total 2 doctors.
There are total 2 singers.
There are total 3 actors.
There are total 3 professors.
我的方法:
(SELECT NAME, '(', SUBSTRING(OCCUPATION, 1, 1), ')'
FROM OCCUPATIONS ORDER BY NAME)
UNION ALL
(SELECT COUNT(*) FROM OCCUPATIONS GROUP BY OCCUPATION ORDER BY ASEC);
错误:
ERROR 1222 (21000) at line 1:
The used SELECT statements have a different number of columns
谢谢!