sql语句实例 取得超过期限的文章

发布时间:2019-09-06编辑:脚本学堂
本文分享下,一段复杂的sql语句代码,取得超过期限的文章,有需要的朋友参考下吧。

取得超过期限文章的sql语句,代码如下:
 

复制代码 代码示例:
SELECT
  page_is_redirect,
  page_title,
  user_name,
  logs.log_timestamp,
  pr_expiry,
  logs.log_comment
FROM page
JOIN page_restrictions ON page_id = pr_page
AND page_namespace = 0
AND pr_type = 'edit'
AND pr_level = 'sysop'
AND pr_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 YEAR),'%Y%m%d%H%i%s')
AND pr_expiry != 'infinity'
LEFT JOIN logging AS logs ON logs.log_title = page_title
                         AND logs.log_namespace = 0
                         AND logs.log_type = 'protect'
LEFT JOIN `user` ON logs.log_user = user_id
WHERE CASE WHEN (NOT ISNULL(log_timestamp))
  THEN log_timestamp = (SELECT MAX(LAST.log_timestamp)
                        FROM logging AS LAST
                        WHERE log_title = page_title
                        AND log_namespace = 0
                        AND log_type = 'protect')
  ELSE 1 END;
 

说明:对文章进行完全保护,一年以上的文章不能再编辑。