可以用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 t.id,
t.pro,
t.createdate,
(SELECT cost
FROM t_cost x
WHERE x.upd_date = (SELECT max(x2.upd_date)
FROM t_cost x2
WHERE t.createdate >= x2.upd_date
and x2.pro = t.pro)
and x.pro = t.pro)
FROM t_order t
订单成本
结果
先取出这个时间范围内的数据:
select count(*) from `tab_time` where `time` between '2015-10-27' and '2015-10-30' group by `time`然后在代码中判断,不存在的,就标记为 0 。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)