嗨,这是我的疑问..
SELECT u.url,u.url_id,@mailid=wu.email FROM urls_uptime_log u INNER JOIN website_suburls wd ON u.url_id=wd.id
INNER JOIN website_to_sms wu ON wd.websiteId=wu.website_id WHERE u.time_stamp>=DATE_SUB(curdate(),INTERVAL 1 DAY) AND u.status<>200
修改: 我得到的输出表是:(此输出包含网站的状态!= 200的网址)
url | url_id |@mailid=wc.email
+-------+------------+----------------
http:/dfg 1616 aaa@gmail.com
+--------+------------+----------------
http:dfff 1621 aaa@gmail.com
+--------+------------+----------------
http:dfff 1619 bbb@ymail.com
我需要查看特定电子邮件的网站数量是多少?我可以使用以下查询吗?
SELECT COUNT(u.url) FROM urls_uptime_log u INNER JOIN website_suburls wd ON u.url_id=wd.id
INNER JOIN website_to_sms wu ON wd.websiteId=wu.website_id WHERE wu.email=@mailid
答案 0 :(得分:2)
要为用户变量赋值,必须使用赋值运算符:=
而不是比较运算符=
。如果你的意思是尝试
SELECT u.url,u.url_id, @mailid := wu.email
FROM urls_uptime_log u JOIN website_suburls wd
ON u.url_id = wd.id JOIN website_to_sms wu
ON wd.websiteId = wu.website_id
WHERE u.time_stamp >= CURDATE() - INTERVAL 1 DAY
AND u.status <> 200
另一方面,如果你只想给列做一个替代名称(别名)
SELECT u.url, u.url_id, wu.email mailid ...
更新:如果没有看到您的表架构,示例数据和所需的输出,很难说,但您可以尝试这样的事情
SELECT COUNT(DISTINCT u.url)
FROM urls_uptime_log u JOIN website_suburls wd
ON u.url_id = wd.id JOIN website_to_sms wu
ON wd.websiteId = wu.website_id
WHERE wu.email IN
(
SELECT DISTINCT wu.email
FROM urls_uptime_log u JOIN website_suburls wd
ON u.url_id = wd.id JOIN website_to_sms wu
ON wd.websiteId = wu.website_id
WHERE u.time_stamp >= CURDATE() - INTERVAL 1 DAY
AND u.status <> 200
)