查询两个表格中的一个

时间:2012-03-25 07:16:44

标签: mysql sql

以下是我在mysql中的表:

        ----------------1-------------------------  
        +---------------------------+----------+
        | email                     | attempts |
        +---------------------------+----------+
        | email1@gmail.com          |       70 |
        | email2@me.com             |        1 |
        | email3@hotmail.com        |        1 |
        | email4@gmail.com          |      115 |
        +---------------------------+----------+
       ---------------2------------------------
        +----------+---------------------------+
        | accesses | email                     |
        +----------+---------------------------+
        |       24 | email1@gmail.com          |
        |        0 | email2@me.com             |
        |        0 | email3@hotmail.com        |
        |       90 | email4@gmail.com          |
        +----------+---------------------------+

在一个

中查询两个表格
Email   Accesses    Attempts
email1    24            70
email2     0             1
email3     0             1
email4    90           115

是sql:

  1. first - > select accesses, email from user;
  2. 秒 - > select email,count(*) as intentos from userstats where intento =1 group by email;
  3. 我该怎么做? 我需要一个查询来绘制。谢谢你提前..

2 个答案:

答案 0 :(得分:1)

SELECT table1.email as Email, 
    table2.accesses as Acesses, 
    table1.attempts as Attempts
from table1 
INNER JOIN table2 
on table1.email = table2.email

答案 1 :(得分:0)

您可以使用INNER JOIN执行此操作

SELECT 
    t1.email, t1.accesses , t2.attempts 
FROM table1 t1
INNER JOIN 
    table2 t2 ON
        t2.email = t1.email;