Board logo

標題: SQL group by data range [打印本頁]

作者: ampm    時間: 2015-4-2 13:44     標題: SQL group by data range

各位師兄,

現有一SQL 想做到Group某一range data

Col B (text data type)
-----
A 234
A 100
A 1.3
A 1.54
AC 67
AB 10.1
AC 5
AB 3852.4
AB 694


Desc                                        |
A 1 - A 100                        A 1.3
                                                                A        1.54
                                                                A 100
----------------------
A 101 - AB 800        A 234
                                                                AB 5
                                                                AB 694
----------------------                                                               
AB 801 - AC 100        AB 3852.4
                                                                AC 5
                                                                AC 67

用SQL 如何做到呢?

Thanks
作者: 紫河馬    時間: 2015-4-2 14:20

select case when xxxxxx else xxxxx end, count()
from ...
where  ...
group by  case when xxxxxx else xxxxx end
作者: ampm    時間: 2015-4-2 14:50

Thank for prompt reply. But Column B is text format, it will affect the grouping. E.G. "A 2" is larger than "A 100"
作者: henrywho    時間: 2015-4-2 16:49

Create a formula to
a) remove all alphabet and space characters from "Column B"
b) convert it to number
c) convert the number to a range indicator, e.g. trunc(NNN/100)





歡迎光臨 電腦領域 HKEPC Hardware (https://h0.hkepc.com/forum/) Powered by Discuz! 7.2