sql 语句实现根据日期字段计算总营业额的查询
程序员文章站
2022-04-26 13:32:13
...
1.实例:
<!-- 计算每天营业总额 -->
<select id="getDayPay" resultType="Customer">
select check_out, sum(pay) sum from customer group by check_out
</select>
<!-- 计算每月营业总额 -->
<select id="getMonthPay" resultType="Customer">
select check_out, sum(pay) sum from customer group by month(check_out) order by check_out
</select>
<!-- 计算每年营业总额 -->
<select id="getYearPay" resultType="Customer">
select check_out, sum(pay) sum from customer group by year(check_out) order by check_out
</select>
2.对每条数据到数据库中测试的结果: