我有一个简单数据的mysql表,例如:



现在,当我执行此简单查询时:

SELECT MAX(cashback) as MAX, MIN(cashback) as MIN FROM pearlcashback_retailers_category WHERE retailer_id='32' AND cashback NOT LIKE '%\%'


它输出:



对于此查询:

SELECT MAX(cashback) as MAX, MIN(cashback) as MIN FROM pearlcashback_retailers_category WHERE retailer_id='32' AND cashback LIKE '%\%'


它输出:



请帮我...



表和数据的SQL:

CREATE TABLE IF NOT EXISTS `pearlcashback_retailers_category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `retailer_id` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `cashback` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;


INSERT INTO `pearlcashback_retailers_category` (`id`, `retailer_id`, `category_id`, `cashback`) VALUES
(1, 32, 17, '46%'),
(2, 32, 14, '40'),
(11, 4, 15, '27%'),
(9, 32, 15, '5'),
(8, 32, 7, '44%'),
(14, 3, 13, '1');

最佳答案

您的现金返还列是VARCHAR,它是一种文本类型,因此min(),max()等均按字母排序(正常)进行操作,因此“ b”>“ aaaa”,当然也包括“ 5”>“ 100” 。

使用正确的类型。

关于php - mysql查询不正确的输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4482634/

10-12 15:28