如何获得每个元素的数量和名称? [英] How to get the count and name of each element?

查看:81
本文介绍了如何获得每个元素的数量和名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从此查询的输出中获取总数:

I want to get the total count from the output of this query:

SELECT category as every, COUNT(*)
FROM categorydata
GROUP BY category

输出看起来像这样:

    every
--------------------------------------  
    TRAI-VPURA  68
    SCHO-VPURA  44
    TECH-BLORE  122
    REAL-VPURA  193
    BIZS-BLORE  2816
    HOSP-VPURA  30
    VIDYARANYAPURA  182
    PLAC-BLORE  461
    business    471
    COLL-VPURA  10
    SOFT-BLORE  362
    TIE-BLORE   95

我想获取总数,即:3538 (as total).我该怎么办?

I want to get the total count, which is: 3538 (as total). How can I do this?

推荐答案

您可以添加with rollup之类的

SELECT category as every, COUNT(*)
FROM categorydata
GROUP BY category
WITH ROLLUP

这将添加总金额的额外记录.

This will add an extra record with the total sum.

修改:
或者,如果您只是只想要总和(没有分组结果),您当然可以做

Edit:
Or, if you just want the total sum (without the group results) you could of course simply do

SELECT COUNT(*) FROM categorydata 

这篇关于如何获得每个元素的数量和名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆