数据库SQL优化

来源:互联网 发布:淘宝拒收可以退款吗 编辑:程序博客网 时间:2024/06/07 03:47
Postgres数据库organization表:CREATE TABLE ORGANIZATION( -- 分公司与部门表DWBH INTEGER NOT NULL, -- 部门IDDWMC VARCHAR(50) NOT NULL, --部门名称FGS INTEGER NOT NULL, --分公司IDFGSMC VARCHAR(50) NOT NULL --分公司名称)优化前:select concat(fgsmc,'---',dwmc) as dwmc from organization where fgsmc!=dwmc union all select distinct dwmc from organization where fgsmc=dwmc优化后:select case when fgsmc!=dwmc then concat(fgsmc,'---',dwmc) when fgsmc=dwmc then dwmc end as dwmc from organization























1 0