0

我想加入AccountANDSales表。

表的主键Accountid,YearCode,AgentId

哪个查询运行得更快

查询 #1:

SELECT * 
FROM account A
     JOIN sales s on a.id = s.id
                     AND a.yearcode = s.yearcode
                     AND a.agentid = s.agentid
WHERE a.yearcode = 1
      AND a.agentid=56
      AND a.id=976

查询 #2:

SELECT *
FROM Account A
     JOIN sales s on a.id=s.id
WHERE s.yearcode=1
      AND s.agentid=56
      AND a.yearcode=1
      AND a.agentid=56
      AND a.id=976

查询 #3:

SELECT *
FROM account a, sales s
WHERE a.id=s.id
      AND a.yearcode=s.yearcode
      AND a.agentid=s.agentid
      AND a.agentid=56
      AND a.yearcode=1
      AND a.id=976
4

1 回答 1

0

尝试这个:

SELECT * 
FROM account A
JOIN sales s on a.id = s.id AND a.yearcode = s.yearcode AND a.agentid = s.agentid
WHERE a.id =976 AND a.yearcode = 1 AND a.agentid=56
于 2012-07-26T11:48:24.107 回答