How to make a condition?
I have request
SELECT IF(f.date_term=3,t.quarter*f.date_term ,''),
IF(f.date_term=6,t.halfyear*f.date_term,''),
IF(f.date_term=12,t.year*开发者_Python百科f.date_term,'')
but this is not work.
how to make a condition? I need one value IF ( date_term == 3 ) {select quarter} ELSE IF ( date_term == 6) {halfyear} ....
Use a CASE expression:
SELECT CASE f.date_term
WHEN 3 THEN t.quarter
WHEN 6 THEN t.halfyear
WHEN 12 THEN t.year
END AS term_interval,
...
There's nothing to stop you from doing the calculation at the same time:
SELECT CASE f.date_term
WHEN 3 THEN t.quarter * f.date_term
WHEN 6 THEN t.halfyear * f.date_term
WHEN 12 THEN t.year * f.date_term
END AS term_calc,
...
精彩评论