在一个查询中,获取姓氏长度,名字长度和按长度分组的三列

时间:2019-05-08 18:36:17

标签: sql oracle18c

我是菜鸟...正在处理家庭作业问题。

具有一个具有last_name,first_name的成员表。我想编写一个查询,该查询按字符串长度汇总last_name,first_name的长度。

输出将包含三列-name_length,count_of_last_names,count_of_first_names。

两个单独的查询:

`SELECT LENGTH(last_name) AS "LnameLen", COUNT(LENGTH(last_name)) AS "CntLnameLen"
FROM members
GROUP BY LENGTH(last_name)
ORDER BY "LnameLen" DESC;

SELECT LENGTH(first_name) AS "FnameLen", COUNT(LENGTH(first_name)) AS "CntFnameLen"
FROM members
GROUP BY LENGTH(first_name)
ORDER BY "FnameLen";`

但是我想编写一个一个查询,该查询输出上述两个查询的工作,因此输出将是三列:Length_of_Name,CntLnameLen,CntFnameLen。

建议?谢谢!

1 个答案:

答案 0 :(得分:0)

按照我对问题的理解方式,类似这样的东西可能就是您要寻找的东西。

select length(first_name), 
       length(last_name),
       count(*)
from members
group by length(first_name), 
         length(last_name);