我需要一个我的sql语句,它选择与此类似的东西
SELECT present, wholeday, attendance
present
和wholeday
被给予,而出席率则由现在和出席者组合生成
if present == 1 and wholeday == 1 then attendance = 1
if present == 1 and wholeday == 0 then attendance = .5
if present == 0 and wholeday == 0 then attendance = 0
答案 0 :(得分:0)
您的查询将是:
SELECT PRESENT, WHOLEDAY,
CASE
WHEN (PRESENT = 1 AND WHOLEDAY = 1) THEN 1
WHEN (PRESENT = 1 AND WHOLEDAY = 0) THEN 0.5
ELSE 0
END as ATTENDANCE
FROM MY_TABLE
Case语法是:
CASE
WHEN condition_1 THEN commands
WHEN condition_2 THEN commands
...
ELSE commands
END CASE;