group by price range

后端 未结 2 1698
半阙折子戏
半阙折子戏 2021-01-12 16:33

Say I have a table of real estate properties:

A  15,000
B  50,000
C 100,000
D  25,000

I\'d like to group them by 0 - 49,999, 50,000 - 99,99

2条回答
  •  春和景丽
    2021-01-12 16:40

    You can GROUP BY an experession, something like that:

    SELECT price/50000*50000 AS minPrice, 
        (price/50000+1)*50000-1 AS maxPrice, 
        COUNT(*)
    FROM table
    GROUP BY price/50000;
    

提交回复
热议问题