Ich möchte eine Liste aller Tags erhalten und wissen, wie viele neue Themen/Beiträge in einem bestimmten Zeitraum (z. B. im letzten Monat) für jedes erstellt wurden.
Kann mir jemand bei der Abfrage helfen?
Man könnte zwar durch Dateien wühlen, aber meiner Meinung nach ist es effizienter, das Menü auf der Plugins-Verwaltungsseite zu nutzen. Du solltest zahlreiche Tabellen sehen können, die bei Auswahl Feldnamen und Schema-Informationen anzeigen.
Ich bin gerade nicht an meinem Desktop, aber das Modell enthält:
# == Schema Information
#
# Table name: topic_tags
#
# id :integer not null, primary key
# topic_id :integer not null
# tag_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_topic_tags_on_topic_id_and_tag_id (topic_id,tag_id) UNIQUE
Beachte die „topic_id
Super, vielen Dank für die Hinweise.
Ich konnte es erfolgreich bauen. Vielleicht ist es nicht perfekt, aber falls es für andere nützlich ist:
Neue Themen pro Tag
-- [params]
-- int :months_ago = 0
WITH query_period as (
SELECT
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' as period_start,
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end
)
SELECT
tags.name,
count(1) as topic_count
FROM topics t
RIGHT JOIN topic_tags tt
ON t.id = tt.topic_id
RIGHT JOIN tags tags
ON tt.tag_id = tags.id
RIGHT JOIN query_period qp
ON t.created_at >= qp.period_start
AND t.created_at <= qp.period_end
WHERE t.user_id > 0
AND tt.topic_id IS NOT NULL
GROUP BY tags.name
ORDER BY topic_count DESC