我在SQL编码方面相当新,我想知道是否有办法可以实现以下语句的尝试结果:
SELECT CASE sc.descrip
WHEN 'x' THEN 'option1' AND 'option2'
ELSE sc.descrip
END as description
FROM status_code sc
不幸的是,'AND'不能以case语句的方式工作。
谢谢,
以下是我正在尝试做的一个例子:
Example | Duration
ShovelA | 3
ShovelB | 5
ShovelC | 7
ShovelD | 9
Example | Duration
A/B Shovels | 8
All Shovels | 24
答案 0 :(得分:1)
Select 'A/B Shovels' as Example,sum(Duration) From status_code
Where Right(Example,1) in ('A','B')
union
Select 'All Shovels' as Example,sum(Duration) From status_code
答案 1 :(得分:1)
我能想到这样做的唯一方法是UNION许多SELECT,每个SELECT都有自己的聚合,例如。
SELECT "A/B Shovels" AS Example, Sum(Duration) AS Duration
FROM status_code
WHERE Example in ("ShovelA", "ShovelB")
UNION
SELECT "All Shovels" AS Example, Sum(Duration) AS Duration
FROM status_code