SQL日期操作函数(CONCAT、DATE_FORMAT、LAST_DAY)
获取某月底日期:SELECT LAST_DAY('2021-07-01') AS month_end_date;
拼接年月格式:
CONCAT(DATE_FORMAT(hp.planned_payment_date, '%Y-%m'), '-01')
如果数据库内存的是2023-07-19
经过处理后会变成:2023-07-01
SELECT bp.UNIT_ID AS UNIT_ID,
hu.unit_name AS project_id_dept,
sum(hp.planned_payment_amount) AS planned_payment_amount_sum,
CONCAT(DATE_FORMAT(hp.planned_payment_date, '%Y-%m'), '-01') AS planned_payment_date,
hp.pay_in_or_out
FROM byjz_fin_all.hlfn_project_position hp
LEFT JOIN byjz_bus.hlpj_project bp ON hp.PROJECT_ID = bp.PROJECT_ID
LEFT JOIN hzero_platform.hpfm_unit hu ON bp.UNIT_ID = hu.UNIT_ID
WHERE hp.forecast_status = 'FORECAST_CONFIRMED'
GROUP BY bp.UNIT_ID,
CONCAT(DATE_FORMAT(hp.planned_payment_date, '%Y-%m'), '-01'), hp.pay_in_or_out
HAVING 1 = 1
ORDER BY unit_id DESC
LIMIT 10;
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/17573442.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地