Between子句不起作用

时间:2013-11-26 11:09:18

标签: mysql

尝试将数量范围设置为0到9 10到19 ... 50 - 99但是当单独完成ieaAmount> 50时返回数据行,类似地a.Amount> 100返回数据行但是后续返回空行。请帮忙截止日期临近! Amount是varchar数据类型。

SELECT   DATE_FORMAT((STR_TO_DATE(a.TRANSACTION_DATE,'%d.%m.%Y')), '%Y%m') mnt, 
         COUNT(DISTINCT a.CUSTOMER_ID) totalNum
FROM    credittx a
WHERE   a.COUNTRY = 'Germany'
        AND a.AMOUNT   BETWEEN   100 AND 50
GROUP   BY DATE_FORMAT((STR_TO_DATE(a.TRANSACTION_DATE,'%d.%m.%Y')),'%Y%m')

3 个答案:

答案 0 :(得分:2)

范围是从 - 到

BETWEEN 50 AND 100

答案 1 :(得分:1)

正如评论中提到的 50小于100 所以请更改:

AND a.AMOUNT BETWEEN 100 AND 50

为:

AND a.AMOUNT BETWEEN 50 AND 100

答案 2 :(得分:1)

在我看来,你必须有50到100之间。不是100和50。

SELECT   
DATE_FORMAT((STR_TO_DATE(a.TRANSACTION_DATE,'%d.%m.%Y')), '%Y%m')   mnt, 
COUNT(DISTINCT a.CUSTOMER_ID) totalNum
FROM    credittx a
 WHERE   a.COUNTRY = 'Germany'
 AND         a.AMOUNT   BETWEEN   50 AND 100
 GROUP   BY DATE_FORMAT((STR_TO_DATE(a.TRANSACTION_DATE,'%d.%m.%Y')),'%Y%m')