select count(1) yjs, case when substr(t.YJB011, 0, 4) = '6301' then '西宁市' when substr(t.YJB011, 0, 4) = '6302' then '海东市' when substr(t.YJB011, 0, 4) = '6322' then '海北藏族自治州' when substr(t.YJB011, 0, 4) = '6323' then '黄南藏族自治州' when substr(t.YJB011, 0, 4) = '6325' then '海南藏族自治州' when substr(t.YJB011, 0, 4) = '6326' then '果洛藏族自治州' when substr(t.YJB011, 0, 4) = '6327' then '玉树藏族自治州' when substr(t.YJB011, 0, 4) = '6328' then '海西蒙古族藏族自治州' else '其他' end qhName from GZZF_YJSJ t group by t.YJB011; 这段sql语句 去重复项
时间: 2024-01-14 07:03:31 浏览: 160
要去除重复项,你可以在原始SQL语句的基础上使用DISTINCT关键字。以下是修改后的SQL语句:
```sql
SELECT COUNT(1) AS yjs,
CASE
WHEN SUBSTR(t.YJB011, 0, 4) = '6301' THEN '西宁市'
WHEN SUBSTR(t.YJB011, 0, 4) = '6302' THEN '海东市'
WHEN SUBSTR(t.YJB011, 0, 4) = '6322' THEN '海北藏族自治州'
WHEN SUBSTR(t.YJB011, 0, 4) = '6323' THEN '黄南藏族自治州'
WHEN SUBSTR(t.YJB011, 0, 4) = '6325' THEN '海南藏族自治州'
WHEN SUBSTR(t.YJB011, 0, 4) = '6326' THEN '果洛藏族自治州'
WHEN SUBSTR(t.YJB011, 0, 4) = '6327' THEN '玉树藏族自治州'
WHEN SUBSTR(t.YJB011, 0, 4) = '6328' THEN '海西蒙古族藏族自治州'
ELSE '其他' END AS qhName
FROM GZZF_YJSJ t
GROUP BY t.YJB011
HAVING qhName = '西宁市' -- 替换 '西宁市' 为要显示的区划名称
ORDER BY yjs DESC; -- 可选:按数量降序排序
```
这将返回去除重复项后的结果,并且你可以选择按照数量降序排序(使用`ORDER BY yjs DESC`)。请替换 `'西宁市'` 为你想要显示数量的具体区划名称。
阅读全文