SQL Group问题

This commit is contained in:
wanggeng 2022-11-23 17:04:03 +08:00
parent 9fd4a82ee3
commit a4e04fb19e

View File

@ -51,51 +51,51 @@
<!-- 历史活动列表 -->
<select id="listActivityHistory" parameterType="map" resultMap="activityLibraryDTO">
SELECT
t1.activity_title,
t1.activity_type,
dt1.data_name activity_type_dictionary_name,
t1.activity_object_oriented,
GROUP_CONCAT(DISTINCT dt2.data_name) activity_object_oriented_dictionary_name,
LEFT(t1.activity_start_time, 10) activity_start_time,
LEFT(t1.activity_end_time, 10) activity_end_time,
t1.activity_start_time start_time,
t1.activity_end_time end_time,
t1.activity_address,
t1.activity_venues,
t1.activity_apply_start_time,
t1.activity_user_num,
t1.activity_apply_end_time,
t1.activity_sponsor,
t1.activity_organizer,
t1.activity_co_organizer,
t1.activity_form_type,
t1.activity_apply_details,
t1.activity_image,
t1.activity_video,
t1.activity_state,
t1.activity_library_id,
t1.activity_address_x,
t1.activity_address_y,
t1.city_name,
t1.county_name,
t1.area_name,
(SELECT COUNT(0) FROM gen_activity_view_num a1 WHERE a1.activity_id = t1.activity_library_id AND a1.is_delete = 0) AS activityViewNum
t1.activity_title,
t1.activity_type,
dt1.data_name activity_type_dictionary_name,
t1.activity_object_oriented,
GROUP_CONCAT(DISTINCT dt2.data_name) activity_object_oriented_dictionary_name,
LEFT(t1.activity_start_time, 10) activity_start_time,
LEFT(t1.activity_end_time, 10) activity_end_time,
t1.activity_start_time start_time,
t1.activity_end_time end_time,
t1.activity_address,
t1.activity_venues,
t1.activity_apply_start_time,
t1.activity_user_num,
t1.activity_apply_end_time,
t1.activity_sponsor,
t1.activity_organizer,
t1.activity_co_organizer,
t1.activity_form_type,
t1.activity_apply_details,
t1.activity_image,
t1.activity_video,
t1.activity_state,
t1.activity_library_id,
t1.activity_address_x,
t1.activity_address_y,
t1.city_name,
t1.county_name,
t1.area_name,
(SELECT COUNT(0) FROM gen_activity_view_num a1 WHERE a1.activity_id = t1.activity_library_id AND a1.is_delete = 0) AS activityViewNum
FROM
gen_activity_library t1
gen_activity_library t1
LEFT JOIN
data_data dt1
data_data dt1
ON
dt1.data_id = t1.activity_type
dt1.data_id = t1.activity_type
AND
dt1.is_delete = 0
dt1.is_delete = 0
LEFT JOIN
data_data dt2
data_data dt2
ON
FIND_IN_SET(dt2.data_id,t1.activity_object_oriented)
FIND_IN_SET(dt2.data_id,t1.activity_object_oriented)
AND
dt2.is_delete = 0
dt2.is_delete = 0
WHERE
t1.is_delete = 0 AND t1.activity_state != 1
t1.is_delete = 0 AND t1.activity_state != 1
<if test="keywords != null and keywords != ''">
AND (
t1.activity_title LIKE CONCAT('%', #{keywords}, '%')
@ -140,25 +140,32 @@
area = #{area}
</if>
GROUP BY
t1.activity_title,
t1.activity_type,
t1.activity_object_oriented,
t1.activity_start_time,
t1.activity_end_time,
t1.activity_address,
t1.activity_venues,
t1.activity_apply_start_time,
t1.activity_user_num,
t1.activity_apply_end_time,
t1.activity_sponsor,
t1.activity_organizer,
t1.activity_co_organizer,
t1.activity_form_type,
t1.activity_apply_details,
t1.activity_image,
t1.activity_video,
t1.activity_state,
t1.activity_library_id
t1.activity_title,
t1.activity_type,
t1.activity_object_oriented,
t1.activity_start_time,
t1.activity_end_time,
t1.activity_address,
t1.activity_venues,
t1.activity_apply_start_time,
t1.activity_user_num,
t1.activity_apply_end_time,
t1.activity_sponsor,
t1.activity_organizer,
t1.activity_co_organizer,
t1.activity_form_type,
t1.activity_apply_details,
t1.activity_image,
t1.activity_video,
t1.activity_state,
t1.activity_library_id,
t1.activity_address_x,
t1.activity_address_y,
dt1.data_name,
t1.city_name,
t1.county_name,
t1.area_name,
t1.gmt_create
ORDER BY t1.gmt_create ASC
</select>