<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xinelu.manage.mapper.orderstatistics.OrderStatisticsMapper">

    <select id="selectAppointmentOrderCount"
            resultType="com.xinelu.manage.vo.orderstatistics.OrderStatisticsVO">
        SELECT ns.nurse_station_name              stationName,
               IFNULL(SUM(aod.order_count), 0)    orderCount,
               IFNULL(SUM(aod.total_price), 0.00) totalPrice
        FROM appointment_order ao
                 LEFT JOIN appointment_order_details aod ON ao.order_no = aod.order_no
                 LEFT JOIN nurse_station_item nsi ON ao.nurse_station_item_id = nsi.id
                 LEFT JOIN nurse_station ns ON nsi.nurse_station_id = ns.id
        WHERE ao.del_flag = 0
          and aod.del_flag = 0
        GROUP BY ns.nurse_station_name,
        ORDER BY orderCount DESC
    </select>
</mapper>