Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Wordpress - Dapatkan jumlah posting DAN komentar setiap hari

Saya pikir ini bukan kueri terbaik yang dapat Anda tulis tetapi tampaknya berhasil

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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Hitung jumlah nilai maksimal untuk beberapa tanggal

  2. Layanan Metastore Hive 1.2 tidak dimulai setelah mengonfigurasinya ke penyimpanan S3, bukan HDFS

  3. Cari teks di bidang di setiap tabel database MySQL

  4. Menghapus baris duplikat dengan sql

  5. PDO dan mengikat beberapa set nilai selama penyisipan - baru-baru ini