目前我的sql语句如下
SELECT NAME,ROUND([DR# BASE]/DAYS_WORKED,0) AS 'BASE/DAY' FROM MYTABLE
输出数据如下所示
NAME BASE/DAY James 300 Jane 310 Jim 313 John 325 Jonah 400
NAME BUCKET BASE/DAY James 300 <= 325 300 Jane 300 <= 325 310 Jim 300 <= 325 313 John 300 <= 325 325 Johnny 325 <= 350 329 Jonah 350 <= 400 400
解决方法
SELECT NAME,CASE WHEN [BASE/DAY] <= 325 THEN '300 <= 325' WHEN [BASE/DAY] <= 350 THEN '325 <= 350' WHEN [BASE/DAY] <= 400 THEN '350 <= 400' END AS BUCKET,[BASE/DAY] FROM ( SELECT NAME,0) AS 'BASE/DAY' FROM MYTABLE ) T ORDER BY 1,2,3