0

I have a question about my code.

SELECT DATE(date_time) dates, SUM(duration/60), customer, provider
FROM cdr_sbc_2017 WHERE
DATE_FORMAT(CONVERT_TZ(disconnect_time,'+07:00','+07:00'),'%Y-%m') =
'2017-09' AND lower(customer) LIKE "%ota%" OR LOWER(customer) LIKE "%alkaip%" OR LOWER(customer) LIKE "%alve%" OR LOWER(customer) LIKE "%antako%"
GROUP BY customer;

I tried like that, but I can't show them all like I want. Can you help me with condition that I used so I can show the customer the name that I want?

thanks.

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • 2
    Welcome to Stack Overflow! Please add more context to your question. In the current state it is hard to tell what the exact problem and/or the expected result is. Please read the [How to ask](//stackoverflow.com/help/how-to-ask) guidelines. – Nrzonline May 13 '18 at 09:15
  • Is this a parenthetical issue? Does wrapping all of the `OR` conditions in a single set of `(` `)` fix the issue? To receive the best possible support, please post an sqlfiddle demo. – mickmackusa May 13 '18 at 09:38
  • ...and I generally stay away from double quoting values in my queries. – mickmackusa May 13 '18 at 09:45
  • Possible duplicate of [How exactly does using OR in a MySQL statement differ with/without parentheses?](https://stackoverflow.com/questions/4872180/how-exactly-does-using-or-in-a-mysql-statement-differ-with-without-parentheses) – mickmackusa May 13 '18 at 10:17

1 Answers1

1

add () around the OR terms. right now its read like (dateformat=... and lower(customer) like "%ota%") or lower(costomer) like... so the current wsintax is:

select DATE(date_time) dates,SUM(duration/60),customer,provider  from cdr_sbc_2017 where DATE_FORMAT(CONVERT_TZ(disconnect_time,'+07:00','+07:00'),'%Y-%m') = '2017-09' and (lower(customer) like "%ota%" or LOWER(customer) like "%alkaip%" or LOWER(customer) like "%alve%" or LOWER(customer) like "%antako%") GROUP BY customer;

the idea is that AND always have a priopity on OR, so foe change it you must to wrap it in ()

Yosef Tukachinsky
  • 5,570
  • 1
  • 13
  • 29
  • That advice sounds familiar. Do you know if this is correct advice? I didn't post it (30 minutes ago) because there is too much missing information in the question. – mickmackusa May 13 '18 at 10:09
  • look at the query. for sure the tems mean to be date and one of the costumer, so even if it is not the quetion, it is somthing that he must to change.. but actually i preety sure that it is the problem in the quetion, and the title is just because he don't know what make the problem to heppen – Yosef Tukachinsky May 13 '18 at 10:13
  • If our advice is correct then this question is a duplicate and should be closed rather than answered. – mickmackusa May 13 '18 at 10:18