dburtsev (dburtsev) wrote,
dburtsev
dburtsev

У MySQL CASE работает?

WITH CTE2 (user_name) AS
(
SELECT 'Asher'
UNION ALL
SELECT 'Cyd'
UNION ALL
SELECT 'Joe'
),
CTE3 (user_name, rating) AS (
SELECT user_name, (FLOOR(0 + RAND() * (5 - 0))) AS rating
FROM CTE2
)
SELECT CTE3.user_name, CTE3.rating,
CASE CTE3.rating
WHEN 0 THEN 'Really bad'
WHEN 1 THEN 'Bad'
WHEN 2 THEN 'Almost bad'
WHEN 3 THEN 'So-so'
WHEN 4 THEN 'OK'
ELSE 'Loved it!'
END
FROM CTE3;
---------------------
"Asher" "4" "Bad"
"Cyd" "2" "Bad"
"Joe" "1" "So-so"
Tags: it
Subscribe

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments