【问题标题】:Use Select query and add its output to text in Oracle [duplicate]使用 Select 查询并将其输出添加到 Oracle 中的文本 [重复]
【发布时间】:2018-06-10 06:02:03
【问题描述】:

我有这张桌子

Name      Occupation
Maria     Actor
Samantha  Doctor
John      Doctor
Kevin     Professor 

我想计算教授的出现并以这种方式输出:

总共有 [occupation_count] [occupation] 个。

我知道如何计算出现次数,但我不知道如何输出消息,有人可以帮我吗?

【问题讨论】:

    标签: sql database oracle


    【解决方案1】:

    您可以在没有group by 的情况下使用它,并借助嵌套在sum 内的decode

    select 'There are a total of ' ||  sum(decode(occupation,'&occupation',1,0)) || ' ' || max(occupation) || 's' "Nr. of Prof's" 
         -- enter Professor whenever prompts, besides you may try other occupations as bind variable
      from  Occupations
    

    Demo

    【讨论】:

      【解决方案2】:
      select 'There are '|| count(*) ||' '|| occupation
      from jobs
      group by occupation
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-18
        • 2022-12-11
        • 1970-01-01
        • 2018-06-13
        • 2018-11-05
        • 2017-02-06
        • 1970-01-01
        相关资源
        最近更新 更多