【发布时间】:2021-02-02 06:13:42
【问题描述】:
我有一个包含两列的表格,如下所示:
total | measure
________________
1 | private vehicle use
4 | private car use
7 | other
我想将前两行合并为一行,将合并行的度量 (strEUCategory) 重命名为“私人车辆使用”。我也想合并总数。 我研究了 CASE 和 PIVOT,但在计算总数的同时无法让它工作。
这是我的查询。
SELECT count(m.strEUCategory) as total , m.strEUCategory as measure
from laqm2_AQAP_measures m
where m.strYearIntroduced <=2020 and m.strCompletionYear >=2020
group by m.strEUCategory
order by m.strEUCategory
【问题讨论】:
-
为了合并行 - 使用
JOIN。请参阅此处的文档:mariadb.com/kb/en/join-syntax
标签: sql string count mariadb case