我想在HYD中添加两个city_name&#39的值(HYD + HYDTC)
CITY_NAME VALUE CCU 10 CHI 12 DEL 15 HYD 20 HYDTC 30 MUM 10
我想以这种方式输出: -
CITY_NAME VALUE CCU 10 CHI 12 DEL 15 HYD 50 MUM 10
答案 0 :(得分:2)
如果要基于前三个字符合并行,则可以使用以下查询:
SELECT LEFT(CITY_NAME, 3) AS CITY_NAME, SUM(VALUE) AS VALUE
FROM mytable
GROUP BY LEFT(CITY_NAME, 3)
答案 1 :(得分:1)
您可以使用CASE
表达式。
<强>查询强>
select t.city_name_alt as city_name, sum(t.value) as value from(
select city_name,
case city_name when 'HYDTC' then 'HYD' else city_name end as city_name_alt,
value
from your_table_name
)t
group by t.city_name_alt;