我不确定术语,但我现在基本上有一个 2 表左连接,如下所示:
Snippets Table
snippet_id PK
snippet_text
snippets_link_email_id Table
snippet_id * (Links to Snippets Table)
email_id * (Links to emails Table)
emails Table
email_id
version_no
许多其他各种数据
所以发生的事情是一个日志被解析并插入到 emails 表中,每条记录都有关于日志文本的详细信息,发现的错误和关于用户的各种信息。
我需要从每个日志中获取的主要信息是错误,每个唯一错误都存储在片段表中。
由于可能有许多电子邮件具有相同的错误,我喜欢运行以下查询以查看有多少唯一错误:
$total_exception_check = mysql_query("SELECT * FROM snippets");
$total_exceptions = mysql_num_rows($total_exception_check);
while ($row = mysql_fetch_array($total_exception_check))
{
$i = $row['snippet_id'];
//Need to find total occurrences of this error
$feedback_query = mysql_query("SELECT * FROM snippets LEFT JOIN snippets_link_email_id ON snippets.snippet_id = snippets_link_email_id.snippet_id WHERE snippets_link_email_id.snippet_id = $i AND snippet_date BETWEEN CURRENT_TIMESTAMP - INTERVAL '$num_days' HOUR AND CURRENT_TIMESTAMP");
}
$tot_snippets = mysql_num_rows($feedback_query);
所以我基本上遍历每个独特的错误,然后搜索snippets_link_email_id 表以查看该错误记录了多少次,即有多少已解析的电子邮件出现了该错误。
tot_snippets 告诉我每个的总量。所以这太棒了,我现在可以为每个错误建立一个表格,以及它被记录了多少次。
然而,在 emails 表中有很多信息,包括版本号,如果我想得到 emails 表中 version_no 的值 = 2000 的总唯一错误怎么办
我将如何编辑此代码以查看它?
SELECT *
FROM snippets
LEFT JOIN snippets_link_email_id
ON snippets.snippet_id = snippets_link_email_id.snippet_id
WHERE
snippets_link_email_id.snippet_id = $i
AND snippet_date BETWEEN
CURRENT_TIMESTAMP - INTERVAL '$num_days' HOUR
AND CURRENT_TIMESTAMP
我从其他类似的帖子中尝试过这个,但我猜我很远:
SELECT *
FROM snippets, emails
LEFT JOIN snippets_link_email_id
ON snippets.snippet_id = snippets_link_email_id.snippet_id
AND snippets_link_email_id.email_id ON emails.email_id
WHERE snippets_link_email_id.snippet_id = $i
AND snippet_date BETWEEN
CURRENT_TIMESTAMP - INTERVAL '$num_days' HOUR AND CURRENT_TIMESTAMP