2015-05-14 92 views
1
id 
1001 
2001 
2002 
3001 
3002 
3003 

如何將id列按其第一位數1, 2, 3分組?我的意思是像下面的東西:按正則表達式計算組

select count(*) from my_tbl group by expr_id_1st_digit; 

count(*) 
1 
2 
3 

回答

1

試試這個:

SELECT Count(*) 
FROM (SELECT Substr(id, 1, 1) AS myGroup 
     FROM table1) a 
GROUP BY mygroup