当前位置: 数据库>sqlserver
sql语句实例 取得超长Ip块的代码
来源: 互联网 发布时间:2014-08-29
本文导语: 1,取得超长IP块,获取超过二年期限的匿名用户信息。 代码示例: SELECT ipb_address, ipb_by_text, ipb_timestamp, ipb_expiry, ipb_reason FROM ipblocks WHERE ipb_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 2 YEAR),'%Y%m%d%H%i%s') AND ipb_expiry != "infin...
1,取得超长IP块,获取超过二年期限的匿名用户信息。
代码示例:
SELECT
ipb_address,
ipb_by_text,
ipb_timestamp,
ipb_expiry,
ipb_reason
FROM ipblocks
WHERE ipb_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 2 YEAR),'%Y%m%d%H%i%s')
AND ipb_expiry != "infinity"
AND ipb_user = 0;
ipb_address,
ipb_by_text,
ipb_timestamp,
ipb_expiry,
ipb_reason
FROM ipblocks
WHERE ipb_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 2 YEAR),'%Y%m%d%H%i%s')
AND ipb_expiry != "infinity"
AND ipb_user = 0;
说明:查询超过二年期限的匿名用户信息。
2,查询无限期保护的文章信息
代码示例:
SELECT
page_is_redirect,
page_title,
user_name,
logs.log_timestamp,
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 = '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;
page_is_redirect,
page_title,
user_name,
logs.log_timestamp,
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 = '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;
说明:获取无限期保护的文章,用到了left join、及case when语句。
有关case when语句的用法,可以参考:
sql case when 日期校验
select case when
case when then else用法