可以用mysql的SUBSTRING_INDEX 函数, 取出~前后的2个数, 变成独立的字段,然后就可以了
比如有表tb_test数据如下图
SELECT id, (SUBSTRING_INDEX(value_range,'~',1)) AS min_value, (SUBSTRING_INDEX(value_range,'~',-1)) AS max_value FROM tb_test
查询结果:
这样就把字符串"xxx~yyy"一个字段,拆分成2个字段了,然后就可以方便的按照需要的条件进行范围查询了
SELECT uptime, CASE WHEN datepart(hour,uptime) IN (0,1) THEN 1WHEN datepart(hour,uptime) IN (2,3) THEN 2
WHEN datepart(hour,uptime) IN (4,5) THEN 3
WHEN datepart(hour,uptime) IN (6,7) THEN 4
WHEN datepart(hour,uptime) IN (8,9) THEN 5
WHEN datepart(hour,uptime) IN (10,11) THEN 6
WHEN datepart(hour,uptime) IN (12,13) THEN 7
WHEN datepart(hour,uptime) IN (14,15) THEN 8
WHEN datepart(hour,uptime) IN (16,17) THEN 9
WHEN datepart(hour,uptime) IN (18,19) THEN 10
WHEN datepart(hour,uptime) IN (20,21) THEN 11
WHEN datepart(hour,uptime) IN (22,23) THEN 12
ELSE 0 END AS sq
FROM bak_dircost0901
-------------------------------
uptime sq
2014/8/19 9:20:59 5
2014/8/22 20:31:20 11
2014/8/22 20:33:08 11
2014/8/26 13:48:01 7
2014/8/27 16:10:45 9
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)