这条sql如何优化最后解释成中文 select sumadvance_gold from artb_charge_record where company_code = atrcompany_code and serial_number = atrserial_number and archive = 0 and state = 0 and atrheating_year heating_ye
这条SQL语句可以优化为:
SELECT SUM(advance_gold) AS tb_last_surplus FROM artb_charge_record WHERE company_code = atr.company_code AND serial_number = atr.serial_number AND archive = 0 AND state = 0 AND atr.heating_year > heating_year AND advance_gold IS NOT NULL AND advance_gold != 0
该语句的意思是:从artb_charge_record表中,筛选出符合条件的记录,其中公司代码(company_code)和序列号(serial_number)与atr表中的相同,存档(archive)和状态(state)都为0,且预付金(advance_gold)不为空且不等于0,加总这些预付金,并将结果命名为tb_last_surplus。
原文地址: https://www.cveoy.top/t/topic/eN5u 著作权归作者所有。请勿转载和采集!