Results 1 to 3 of 3

Thread: MySQL 'CASE'

  1. #1
    Join Date
    Jul 2004

    Unanswered: MySQL 'CASE'

    I have a query in MSSQL like this:
    select table1.*, 
    CASE WHEN field1 > '10000' THEN '1'
    WHEN field2 BETWEEN '5001' AND '9999' THEN '2'
    WHEN field3 BETWEEN '2501' AND '5000' THEN '3'
    WHEN field4 BETWEEN '0' AND '2500' THEN '4'
    AS Class
    FROM table1
    How do I convert this to MySQL?
    Last edited by dhoward; 08-04-04 at 22:45.

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I'd use MySQL's CASE, which should work just like MS-SQL's CASE. I'm highly suspicious that you didn't mean to use different column names (Field1 through Field4 in your example). That would be a bad thing in most cases!


  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
    Quote Originally Posted by dhoward
    How do I convert this to MySQL?
    by adding the manadory END keyword, which i believe is also mandatory in sql server

    i agree with pat, youprobably did mean to use the same field name in each WHEN condition, right? | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts