refactor: 更改子查询为join
This commit is contained in:
@@ -136,7 +136,6 @@
|
||||
</select>
|
||||
|
||||
<select id="queryCourseOrder" resultType="com.sqx.modules.app.response.CourseOrderResponse">
|
||||
select * from (
|
||||
select c.course_id as courseId,sum(o.pay_money) as 'coursemoney' ,count(*) as 'coursenum',any_value(c.title) as 'coursename'
|
||||
from orders o
|
||||
left join course c on o.course_id=c.course_id
|
||||
@@ -154,8 +153,7 @@
|
||||
and date_format(o.create_time,'%Y')=date_format(#{date},'%Y')
|
||||
</if>
|
||||
group by c.course_id
|
||||
) a
|
||||
order by a.coursenum desc
|
||||
order by coursenum desc
|
||||
</select>
|
||||
<select id="userMessage" resultType="int">
|
||||
select count(*) from tb_user t
|
||||
@@ -335,4 +333,4 @@
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@@ -6,6 +6,34 @@
|
||||
|
||||
<select id="selectCourseByCollect" resultType="com.sqx.modules.course.entity.Course">
|
||||
SELECT
|
||||
MAX(u.update_time) AS produceEndTime,
|
||||
c.*,
|
||||
d1.course_details_name AS courseDetailsName,
|
||||
d1.course_details_id AS courseDetailsId,
|
||||
COUNT(d2.course_details_id) AS courseDetailsCount
|
||||
FROM
|
||||
course_collect u
|
||||
LEFT JOIN
|
||||
course c ON u.course_id = c.course_id
|
||||
LEFT JOIN
|
||||
course_collect cc1 ON cc1.course_id = u.course_id
|
||||
AND cc1.classify = 3
|
||||
AND cc1.user_id = #{userId}
|
||||
LEFT JOIN
|
||||
course_details d1 ON cc1.course_details_id = d1.course_details_id
|
||||
LEFT JOIN
|
||||
course_details d2 ON d2.course_id = c.course_id
|
||||
WHERE
|
||||
u.user_id = #{userId}
|
||||
AND c.course_id IS NOT NULL
|
||||
AND u.classify = #{classify}
|
||||
GROUP BY
|
||||
u.course_id, c.course_id
|
||||
ORDER BY
|
||||
produceEndTime DESC;
|
||||
|
||||
|
||||
<!-- SELECT
|
||||
MAX( u.update_time ) AS produceEndTime,
|
||||
c.*,
|
||||
(
|
||||
@@ -46,6 +74,7 @@
|
||||
u.course_id
|
||||
ORDER BY
|
||||
produceEndTime DESC
|
||||
-->
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@@ -7,6 +7,103 @@
|
||||
where course_id = #{id}
|
||||
</update>
|
||||
<select id="selectCourse" resultType="Map">
|
||||
|
||||
SELECT
|
||||
c.classify_id AS classifyId,
|
||||
c.course_id AS courseId,
|
||||
c.course_label AS courseLabel,
|
||||
c.create_time AS createTime,
|
||||
c.details,
|
||||
c.img,
|
||||
c.banner_img AS bannerImg,
|
||||
c.status,
|
||||
c.is_delete AS isDelete,
|
||||
c.msg_type AS msgType,
|
||||
c.msg_url AS msgUrl,
|
||||
c.pay_num AS payNum,
|
||||
c.price,
|
||||
c.wholesale_price AS wholesalePrice,
|
||||
c.is_over AS isOver,
|
||||
c.title,
|
||||
c.is_price AS isPrice,
|
||||
c.title_img AS titleImg,
|
||||
c.update_time AS updateTime,
|
||||
cc.classification_name AS classificationName,
|
||||
c.course_type AS courseType,
|
||||
c.banner_id AS bannerId,
|
||||
b.name AS bannerName,
|
||||
0 AS viewCounts,
|
||||
c.dy_img_id AS dyImgId,
|
||||
c.dy_course_id AS dyCourseId,
|
||||
c.wx_course_id AS wxCourseId,
|
||||
c.wx_show AS wxShow,
|
||||
c.dy_show AS dyShow,
|
||||
c.sort,
|
||||
0 AS goodNum,
|
||||
d.courseDetailsCount,
|
||||
NULL AS courseDetailsName,
|
||||
NULL AS courseDetailsId,
|
||||
0 AS weekGoodNum,
|
||||
0 AS isRecommend
|
||||
FROM
|
||||
course AS c
|
||||
LEFT JOIN
|
||||
course_classification AS cc ON c.classify_id = cc.classification_id
|
||||
LEFT JOIN
|
||||
banner AS b ON b.id = c.banner_id
|
||||
LEFT JOIN
|
||||
(SELECT course_id, COUNT(*) AS courseDetailsCount FROM course_details GROUP BY course_id) AS d
|
||||
ON c.course_id = d.course_id
|
||||
WHERE
|
||||
c.is_delete = 0
|
||||
<if test='null != wxShow and wxShow == 1'>
|
||||
AND c.wx_show = #{wxShow}
|
||||
</if>
|
||||
<if test='null != wxShow and wxShow == 2'>
|
||||
AND (c.wx_show = #{wxShow} OR c.wx_show IS NULL)
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow == 1'>
|
||||
AND c.dy_show = #{dyShow}
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow == 2'>
|
||||
AND (c.dy_show = #{dyShow} OR c.dy_show IS NULL)
|
||||
</if>
|
||||
<if test='null != title'>
|
||||
AND c.title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test='null != classifyId and classifyId != 0'>
|
||||
AND c.classify_id = #{classifyId}
|
||||
</if>
|
||||
<if test='null != bannerId and bannerId != 0'>
|
||||
AND c.banner_id = #{bannerId}
|
||||
</if>
|
||||
<if test="classifyId == 0">
|
||||
AND c.is_recommend = 1
|
||||
</if>
|
||||
<if test="over != null">
|
||||
AND c.is_over = #{over}
|
||||
</if>
|
||||
<if test="isRecommend != null and isRecommend != -1">
|
||||
AND c.course_id IN (SELECT course_id FROM course_details WHERE good = 1)
|
||||
</if>
|
||||
<if test="status != null and status != 0">
|
||||
AND c.status = #{status}
|
||||
</if>
|
||||
<if test="isPrice != null">
|
||||
AND c.is_price = #{isPrice}
|
||||
</if>
|
||||
<if test="wxCourse != null">
|
||||
AND c.wx_course_id IS NOT NULL
|
||||
</if>
|
||||
<if test="dyCourse != null">
|
||||
AND c.dy_status = 4
|
||||
</if>
|
||||
ORDER BY
|
||||
c.sort ASC, c.create_time DESC;
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
SELECT
|
||||
c.classify_id as classifyId,
|
||||
c.course_id as courseId,
|
||||
@@ -94,7 +191,8 @@
|
||||
and c.dy_status=4
|
||||
</if>
|
||||
order by c.sort asc,c.create_time desc
|
||||
<!--
|
||||
|
||||
分割线
|
||||
<if test="sort==null">
|
||||
order by c.sort asc
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user