Categories
post

Conditional Statements in Mysql (if/case/etc)

I never really thought to ask the question, but was shocked to see you can do simple conditional statements in Mysql. This will make my querying far better than in the past. Plus I can pull quick data when needed instead of writing a script to analyze it.

Example, trying to find out if an order was placed in our callcenter or on the web:

SELECT orderDate, if(ipAddress = ‘XXX.XXX.XXX.XXX’, ‘CallCenter’, ‘Web’) as WherePlaced, count(*) as cnt FROM orders GROUP BY orderDate, WherePlaced

Simple, but only useful if you know about it. Now I do. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *