0

Trying to set amount range like 0 to 9 10 to 19 ... 50 - 99 but when done individually i.e. a.Amount >50 returns data rows and similarly a.Amount >100 returns data rows but the follwing returns null rows. Please help deadline is near! The Amount is a varchar data type.

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') 
0

3 Answers 3

2

The range is from-to

do BETWEEN 50 AND 100

Sign up to request clarification or add additional context in comments.

Comments

1

Seems to me that you must have between 50 AND 100. Not 100 AND 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') 

Comments

1

As mentioned in the comment that 50 is less than 100 so please change:

AND a.AMOUNT BETWEEN 100 AND 50

to:

AND a.AMOUNT BETWEEN 50 AND 100 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.