1

嗨,这是我的查询..

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

编辑:我得到的输出表是:(此输出包含站点的 url 状态!=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
4

1 回答 1

3

要将值分配给用户变量,您必须使用赋值运算符:=而不是比较运算符=。如果你真的想试试

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
)
于 2013-09-19T03:58:27.217 回答