SQL: 在单独的 header 下复制数据
SQL: Duplicating data under a separate header
我对 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
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
我能想到的唯一方法是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
我对 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
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
我能想到的唯一方法是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