sql >> Database >  >> RDS >> Mysql

Wordpress - Krijg het aantal berichten EN reacties per dag

Ik denk dat dit niet de beste vraag is die je kunt schrijven, maar het lijkt te werken

CREATE VIEW commentsCount (date, counter) AS
SELECT
    DISTINCT DATE(comment_date) AS date,
    IFNULL(COUNT(comment_ID),0) AS total
FROM wp_comments
GROUP BY date ORDER BY total DESC
CREATE VIEW postsCount (date, counter) AS
SELECT
    DISTINCT DATE(post_date) AS date,
    IFNULL(COUNT(ID),0) AS total
FROM wp_posts
GROUP BY date ORDER BY total DESC
SELECT
    postsCount.date,
    IFNULL(postsCount.counter,0),
    IFNULL(commentsCount.counter,0),
    (IFNULL(postsCount.counter,0)*10 + IFNULL(commentsCount.counter, 0))
FROM commentsCount RIGHT JOIN postsCount 
    ON DATE(postsCount.date) = DATE(commentsCount.date)
GROUP BY postsCount.date
union
SELECT
    commentsCount.date,
    IFNULL(postsCount.counter,0),
    IFNULL(commentsCount.counter,0),
    (IFNULL(postsCount.counter,0)*10 + IFNULL(commentsCount.counter, 0))
FROM commentsCount LEFT JOIN postsCount 
    ON DATE(postsCount.date) = DATE(commentsCount.date)
GROUP BY commentsCount.date



  1. Terminal herkent mysqld- en mysql-opdrachten niet

  2. Kan SQLite-database niet openen vanuit SQLIte Helper Oncreate, wanneer OnCreate wordt geactiveerd door de database voor de eerste keer te openen

  3. Oci_connect-functie is niet gedefinieerd in CentOS met Oracle

  4. Failover &Failback voor PostgreSQL op Microsoft Azure