10 changed files with 1054 additions and 90 deletions
			
			
		@ -0,0 +1,167 @@
					 | 
				
			||||
package com.mh.user.dto; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
 | 
				
			||||
public class EnergyMomYoyDataDTO { | 
				
			||||
 | 
				
			||||
    private String curDate; | 
				
			||||
 | 
				
			||||
    private BigDecimal elect; | 
				
			||||
 | 
				
			||||
    private BigDecimal cl; | 
				
			||||
 | 
				
			||||
    private BigDecimal cop; | 
				
			||||
 | 
				
			||||
    private BigDecimal lastElect; | 
				
			||||
 | 
				
			||||
    private BigDecimal lastCl; | 
				
			||||
 | 
				
			||||
    private BigDecimal lastCop; | 
				
			||||
 | 
				
			||||
    private String electRatio; | 
				
			||||
 | 
				
			||||
    private String clRatio; | 
				
			||||
 | 
				
			||||
    private String copRatio; | 
				
			||||
 | 
				
			||||
    private String projectId; | 
				
			||||
 | 
				
			||||
    private String projectName; | 
				
			||||
 | 
				
			||||
    private String ambTemp; | 
				
			||||
 | 
				
			||||
    private String humidity; | 
				
			||||
 | 
				
			||||
    public String getProjectName() { | 
				
			||||
        return projectName; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setProjectName(String projectName) { | 
				
			||||
        this.projectName = projectName; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getAmbTemp() { | 
				
			||||
        return ambTemp; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setAmbTemp(String ambTemp) { | 
				
			||||
        this.ambTemp = ambTemp; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getHumidity() { | 
				
			||||
        return humidity; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setHumidity(String humidity) { | 
				
			||||
        this.humidity = humidity; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCurDate() { | 
				
			||||
        return curDate; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setCurDate(String curDate) { | 
				
			||||
        this.curDate = curDate; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getElect() { | 
				
			||||
        return elect; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setElect(BigDecimal elect) { | 
				
			||||
        this.elect = elect; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getCl() { | 
				
			||||
        return cl; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setCl(BigDecimal cl) { | 
				
			||||
        this.cl = cl; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getCop() { | 
				
			||||
        return cop; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setCop(BigDecimal cop) { | 
				
			||||
        this.cop = cop; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getLastElect() { | 
				
			||||
        return lastElect; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setLastElect(BigDecimal lastElect) { | 
				
			||||
        this.lastElect = lastElect; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getLastCl() { | 
				
			||||
        return lastCl; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setLastCl(BigDecimal lastCl) { | 
				
			||||
        this.lastCl = lastCl; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public BigDecimal getLastCop() { | 
				
			||||
        return lastCop; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setLastCop(BigDecimal lastCop) { | 
				
			||||
        this.lastCop = lastCop; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getElectRatio() { | 
				
			||||
        return electRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setElectRatio(String electRatio) { | 
				
			||||
        this.electRatio = electRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getClRatio() { | 
				
			||||
        return clRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setClRatio(String clRatio) { | 
				
			||||
        this.clRatio = clRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCopRatio() { | 
				
			||||
        return copRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setCopRatio(String copRatio) { | 
				
			||||
        this.copRatio = copRatio; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getProjectId() { | 
				
			||||
        return projectId; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public void setProjectId(String projectId) { | 
				
			||||
        this.projectId = projectId; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    public String toString() { | 
				
			||||
        return "EnergyMomYoyDataDTO{" + | 
				
			||||
                "curDate='" + curDate + '\'' + | 
				
			||||
                ", elect=" + elect + | 
				
			||||
                ", cl=" + cl + | 
				
			||||
                ", cop=" + cop + | 
				
			||||
                ", lastElect=" + lastElect + | 
				
			||||
                ", lastCl=" + lastCl + | 
				
			||||
                ", lastCop=" + lastCop + | 
				
			||||
                ", electRatio='" + electRatio + '\'' + | 
				
			||||
                ", clRatio='" + clRatio + '\'' + | 
				
			||||
                ", copRatio='" + copRatio + '\'' + | 
				
			||||
                ", projectId='" + projectId + '\'' + | 
				
			||||
                ", projectName='" + projectName + '\'' + | 
				
			||||
                ", ambTemp='" + ambTemp + '\'' + | 
				
			||||
                ", humidity='" + humidity + '\'' + | 
				
			||||
                '}'; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,255 @@
					 | 
				
			||||
-- 小时同比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t2.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        when t2.elect = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        when t2.cl = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        when t2.cop = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ':00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_hour edh1 | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-11-22 00' | 
				
			||||
          and cur_date <= '2024-11-22 23' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ':00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_hour | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023-11-22 00' | 
				
			||||
          and cur_date <= '2023-11-22 23' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 日同比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t2.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        when t2.elect = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        when t2.cl = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        when t2.cop = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ' 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_day | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-07-01' | 
				
			||||
          and cur_date <= '2024-07-22' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ' 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_day | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023-07-01' | 
				
			||||
          and cur_date <= '2023-07-22' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 月同比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t2.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        when t2.elect = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        when t2.cl = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        when t2.cop = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_month | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-01' | 
				
			||||
          and cur_date <= '2024-11' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_month | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023-01' | 
				
			||||
          and cur_date <= '2023-07' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 年同比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t2.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        when t2.elect = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        when t2.cl = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        when t2.cop = 0 then '0' | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_year | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023' | 
				
			||||
          and cur_date <= '2024' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_year | 
				
			||||
        where | 
				
			||||
            cur_date >= '2022' | 
				
			||||
          and cur_date <= '2023' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
@ -0,0 +1,239 @@
					 | 
				
			||||
-- 小时环比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ':00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_hour edh1 | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-11-22 00' | 
				
			||||
          and cur_date <= '2024-11-22 23' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ':00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_hour | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-11-21 23' | 
				
			||||
          and cur_date <= '2024-11-22 22' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(hour, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 日环比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ' 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_day | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-11-01' | 
				
			||||
          and cur_date <= '2024-11-22' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, ' 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_day | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-10-31' | 
				
			||||
          and cur_date <= '2024-11-21' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(day, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 月环比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_month | 
				
			||||
        where | 
				
			||||
            cur_date >= '2024-01' | 
				
			||||
          and cur_date <= '2024-12' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_month | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023-12' | 
				
			||||
          and cur_date <= '2024-11' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(month, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
 | 
				
			||||
-- 年环比 | 
				
			||||
select | 
				
			||||
    t1.cur_date, | 
				
			||||
    t1.elect, | 
				
			||||
    t1.cl, | 
				
			||||
    t1.cop, | 
				
			||||
    t1.project_id, | 
				
			||||
    t2.elect as last_elect, | 
				
			||||
    t2.cl as last_cl, | 
				
			||||
    t2.cop as last_cop, | 
				
			||||
    case | 
				
			||||
        when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_elect, | 
				
			||||
    case | 
				
			||||
        when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cl, | 
				
			||||
    case | 
				
			||||
        when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') | 
				
			||||
        else '上期无数据' | 
				
			||||
        end mom_cop | 
				
			||||
from | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_year | 
				
			||||
        where | 
				
			||||
            cur_date >= '2023' | 
				
			||||
          and cur_date <= '2024' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t1 | 
				
			||||
        left join | 
				
			||||
    ( | 
				
			||||
        select | 
				
			||||
            cur_date, | 
				
			||||
            elect, | 
				
			||||
            cl, | 
				
			||||
            cop, | 
				
			||||
            project_id, | 
				
			||||
            convert(datetime, | 
				
			||||
                    concat(cur_date, '-01-01 00:00:00')) as change_cur_date | 
				
			||||
        from | 
				
			||||
            energy_data_year | 
				
			||||
        where | 
				
			||||
            cur_date >= '2022' | 
				
			||||
          and cur_date <= '2023' | 
				
			||||
          and project_id = 3 | 
				
			||||
    ) t2 | 
				
			||||
    on | 
				
			||||
        t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) | 
				
			||||
order by t1.cur_date | 
				
			||||
					Loading…
					
					
				
		Reference in new issue