|
|
@@ -116,4 +116,36 @@
|
|
|
)d1
|
|
|
);
|
|
|
</select>
|
|
|
+
|
|
|
+ <select id="monthProfit" parameterType="long" resultType="string">
|
|
|
+ select concat('[',five_profit,',',other_profit,']') from (
|
|
|
+ (
|
|
|
+ #前5数据
|
|
|
+ select group_concat('{"x":"',custname,'","y":',profit,',"z":"',shortname,'"}') five_profit from (
|
|
|
+ select sum((ifnull(pd_netprice,0)- ifnull(pd_price,0))*(ifnull(pd_outqty,0) - ifnull(pd_inqty,0))) profit,
|
|
|
+ pi_custcode,max(pi_custname) custname,max(ifnull(cu_shortname,'')) shortname from prodinout left join prodiodetail on pi_id=pd_piid left join customer on cu_id=pi_custid
|
|
|
+ where
|
|
|
+ pi_class in('出货单', '销售退货单') and pi_statuscode='AUDITED' and DATE_FORMAT(pi_date,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m') and prodinout.companyid=#{componyId}
|
|
|
+ GROUP BY pi_custcode,prodinout.companyid order by profit desc limit 0,4) t
|
|
|
+ )five_profit_,
|
|
|
+ (
|
|
|
+ #其它的数据
|
|
|
+ select concat('{"z":"其它","x":"其它","y":',all_profit - five_profit,'}') other_profit from (
|
|
|
+ #总共
|
|
|
+ (
|
|
|
+ select sum((ifnull(pd_netprice,0)- ifnull(pd_price,0))*(ifnull(pd_outqty,0) - ifnull(pd_inqty,0))) all_profit
|
|
|
+ from prodinout left join prodiodetail on pi_id=pd_piid
|
|
|
+ where
|
|
|
+ pi_class in('出货单', '销售退货单') and pi_statuscode='AUDITED' and DATE_FORMAT(pi_date,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m') and prodinout.companyid=#{componyId} )a1_,
|
|
|
+ #前5总和
|
|
|
+ (
|
|
|
+ select sum(profit) five_profit from (select sum((ifnull(pd_netprice,0)- ifnull(pd_price,0))*(ifnull(pd_outqty,0) - ifnull(pd_inqty,0))) profit,
|
|
|
+ pi_custcode,max(pi_custname) custname,prodinout.companyid from prodinout left join prodiodetail on pi_id=pd_piid left join customer on cu_id=pi_custid
|
|
|
+ where
|
|
|
+ pi_class in('出货单', '销售退货单') and pi_statuscode='AUDITED' and DATE_FORMAT(pi_date,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m') and prodinout.companyid=#{componyId}
|
|
|
+ GROUP BY pi_custcode,prodinout.companyid order by profit desc limit 0,4) b)a2_
|
|
|
+ )
|
|
|
+ ) other_profit_
|
|
|
+ )
|
|
|
+ </select>
|
|
|
</mapper>
|