解决方案 »
- 一个让人百思不得其解的结果
- java.sql.SQLException: Table 'xxx' is marked as crashed and should be ...
- 使用JAVA向MYSQL的BLOB类型,插入一个大文件,如何解决OutOfMemoryError问题!
- MYSQL数据插入时错误,请来看下
- postgres COPY 问题,谢谢.
- 帮我看看该怎么写这个Mysql存储过程啊
- mydql修改问题
- 应用程序如何感知mysql数据库变化?
- mysql.select语句里怎样批量的在一个字段前面加指定字符?也就是update语句怎样写才能实现?
- Grant创建的用户名无法登录数据库
- mysql有什么办法批量去掉某个字段字符中间的空格
- mysql 报表
小于3000:<3000
2000到3000之间: between 2000 and 3000MSSQL的这样写就包括了2000和3000这两个值在内。MYSQL的不清楚
id salary
-----------------
1 2000-3000
----------------
2 4000-5000
*/--生成测试数据:
go
if OBJECT_ID('tbl') is not null
drop table tbl
go
create table tbl(
id int,
salary varchar(10)
)
go
insert tbl
select 1,'2001-3000' union all
select 2,'3001-4000' union all
select 3,'4001-5000' union all
select 4,'5001-6000' union all
select 5,'6001-7000'select *from tblselect *from tbl where cast(LEFT(salary,CHARINDEX('-',salary)-1) as int) between 2000 and 5000
and cast(right(salary,CHARINDEX('-',salary)-1) as int) between 2000 and 5000/*
id salary
1 2001-3000
2 3001-4000
3 4001-5000
*/MSSQL中可以这样实现,MYSQL应该也是这样
http://zhidao.baidu.com/question/323155827.html
FROM `work`
WHERE substring_index(`salary` ,'-',1)+0 <=3000
and substring_index(`salary` ,'-',-1)+0 >=3000
-----------------
1 2000-3000
----------------
2 4000-5000+======================
salary 这个字段的类型是字符串吧,用 between 这个比较合适吗?你保存的就是一个范围,这不是自己找麻烦吗
(id ,min_num ,max_num)
容易处理一点