2

I'm using the following query:

select a.idclientecrm, max(c.falta) from clientescrmporlistadeclientescrm a
inner join clientescrmporlistadeclientescrm b on (a.idclientecrm=b.idclientecrm and   a.idlistadeclientescrm = 58)
inner join tareas c on a.idclientecrm=c.idclientecrm
where b.idlistadeclientescrm = 70

But I'm not getting the result I want. I know I'm doing something wrong but I don't know what.

I want the outcome of the first inner join (aprox 22k rows) but I need to join the result to the "tareas" table and get the max date from there.

I want to use max because for every idclientecrm, there's more than one row that matches in the "tareas" table and I need the last recorded result.

If I left out something let me know.

Thnx in advance!

4

1 回答 1

1

您可能希望将“58”条件移动到 A.idclientecrm 上的 WHERE 子句和组:

select a.idclientecrm, max(c.falta) 
from clientescrmporlistadeclientescrm a
inner join clientescrmporlistadeclientescrm b 
on a.idclientecrm = b.idclientecrm
inner join tareas c 
on a.idclientecrm = c.idclientecrm
where b.idlistadeclientescrm = 70
and a.idlistadeclientescrm = 58
group by a.idclientecrm
于 2013-05-13T21:16:03.590 回答