mysql查询以下表

时间:2012-03-01 11:49:06

标签: mysql

如何对以下表格进行一次Mysql查询,以便在以下条件中查找电子邮件字段,

但条件是,
来自comp table = 1的advisorid和来自trance table = 1和
的receiverid 2.当两个表的日期介于'2012-02-01'和'2012-02-30'之间时。
请帮忙,
提前致谢。

4 个答案:

答案 0 :(得分:1)

您可以使用left函数从trance表中获取receiverid中的正确数字。

select c.email 
from comp c INNER JOIN trance t
on c.id = t.id
where (c.advisorid = 1 and left(t.receiverid,1) = 1) 
and (c.changedate between '2012-02-30' and '2012-02-01')
and (t.date between '2012-02-30' and '2012-02-01');

答案 1 :(得分:0)

我不知道你需要哪些数据(列),但试试这个:

SELECT * FROM comp c, trance t WHERE c.advisorid = 1 
AND t.receiverid = 1 
AND c.changedate BETWEEN '2012-02-01' AND '2012-02-30'
AND t.date BETWEEN '2012-02-01' AND '2012-02-30'

答案 2 :(得分:0)

SELECT c.email AS EMAIL
FROM trance t, comp c
WHERE  c.advisorid = 1 
   AND t.receiverid = 1 
   AND c.changedate BETWEEN '2012-02-01' AND '2012-02-30'
   AND t.date BETWEEN '2012-02-01' AND '2012-02-30

答案 3 :(得分:0)

try this query..


select * from comp as a INNER JOIN trance as b ON a.id=b.id WHERE a.advisorid=1 AND b.receiverid=1 AND (a.changedate >='2012-02-01' and a.changedate <= '2012-02-30') AND (b.date >='2012-02-01' and b.date'<='2012-02-30')