本文介绍了如何使用BETWEEN,COUNT和ALIAS显示数字范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用BETWEEN,COUNT和ALIAS显示同一列中数字范围的数字范围。

比如10-19,20-29等等

请帮助我!!我被困了



我尝试过:



选择性别,计数(年龄)从表1中的'10 -19'

其中年龄在10和19之间

GROUP BY SEX



上面的代码对我来说很好。



但是对于其他数字范围,我被困住了。请在论坛中擅长Pls帮助!!

How do I display ranges of numbers using BETWEEN, COUNT and ALIAS for ranges of numbers in the same column .
Say 10-19, 20-29, e.t.c
Pls kindly help me!! I'm stuck

What I have tried:

Select Sex, Count(Age) as '10-19' from Table1
Where AGE BETWEEN 10 and 19
GROUP BY SEX

The code above works fine for me.

But for other ranges of numbers I am stuck. Pls my good in the forum Pls help!!

推荐答案

SELECT
    Sex,
    Sum(CASE WHEN Age BETWEEN 10 And 19 THEN 1 ELSE 0 END) As '10-19',
    Sum(CASE WHEN Age BETWEEN 20 And 29 THEN 1 ELSE 0 END) As '20-29',
    ...
FROM
    Table1
GROUP BY
    Sex


这篇关于如何使用BETWEEN,COUNT和ALIAS显示数字范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:03