mysql varchar 查询问题 ?

mysql varchar 查询问题 


30秒到达战场
浏览 1361回答 5
5回答

陪伴而非守候

根据你1,2点原因我做出如下推断:你导进去的数据daihao字段varchar是否包含了空格或者其它特殊字符,或者存在编码问题;select * from a where daihao= 18这个查询工具自动转成了数字类型,肯定是查询没有问题的。

缥缈止盈

直接用> < 啊比如select * from 表 where 字段 > 100---补充你什么数据库啊。varchar类型也可以用。create table test(col1 varchar(2))declare @i intset @i = 1while @i< 100begininsert into test values(convert(varchar(2),@i))set @i = @i + 1endselect * from test where col1 > 50 --正确select * from test where convert(numeric(10),col1) > 50 --正确select * from test where col1 > '50' --错误drop table test你自己测试吧如果你非要把类型转成数值型也可以但这是用不到索引了

守着一只汪

可以把varchar转换成别的类型比如 decimal,float之类例:select * from 表 where convert(float,字段)>100

哆啦的时光机

条件语句where id != '1' and id != '2' --id字段为char、nchar、varchar型等等或where id != 1 and id != 2 --id字段为int、smallint型

慕侠2389804

查询的时候加个这个,distincy,举个例子:$list['pay_user'] = $this->get_table("orders")->where("pay_time>=$time2 and pay_time<$time1 and is_recharge=%d and statu=%d",1,1)->count('DISTINCT username');就这样,你就可以查出不相同的字段了
打开App,查看更多内容
随时随地看视频慕课网APP