En meget hacket løsning er at få thread_id
sorteret efter view_count
i en GROUP_CONCAT
. Derefter kan vi bruge strengoperationer til at få thread_id
med minimum view_count
.
I din SELECT
klausul i stedet for t.thread_id
, kan du prøve følgende:
SUBSTRING_INDEX(GROUP_CONCAT(DISTINCT t.thread_id
ORDER BY t.view_count ASC
SEPARATOR ','),
',',
1) AS thread_id_with_minimum_views
Nu, baseret på SELECT
forespørgsel for at identificere duplikerede poster med Minimum visning, DELETE
forespørgsel om at slette sådanne poster fra xf_thread
tabel vil være som følger:
DELETE t_delete FROM xf_thread AS t_delete
INNER JOIN (SELECT CAST(SUBSTRING_INDEX(GROUP_CONCAT(DISTINCT t.thread_id ORDER BY t.view_count ASC SEPARATOR ','), ',', 1) AS UNSIGNED) AS tid_min_view
FROM (SELECT * FROM xf_thread) t
INNER JOIN xf_post p ON p.thread_id = t.thread_id
WHERE t.first_post_id = p.post_id
AND t.user_id = 0
AND t.reply_count < 2
GROUP BY t.title, t.username, p.message
HAVING Count(t.title) > 1
AND Count(t.username) > 1
AND Count(p.message) > 1
ORDER BY t.thread_id) AS t_dup
ON t_delete.thread_id = t_dup.tid_min_view