Jump to content
Fivewin Brasil

Ajuda com SELECT


Luiz Fernando

Recommended Posts

Colegas o MAX não seria para funcionar no WHERE , qdo tendo fazer isto o retorno é sempre nulo, preciso da relação de clientes que não tem movimento anterior a uma data...

cSql="SELECT '',v.cliente,c.razao,date_format(max(v.data),'%d/%m/%Y')"
cSql+=" FROM vendas as v"
cSql+=" LEFT JOIN cliente as c on v.cliente = c.cod_client"
cSql+=" WHERE max(v.data) <"+Any2Sql(cGet[1])
cSql+=" GROUP BY v.cliente"
cSql+=" ORDER BY v.cliente"

Link to comment
Share on other sites

Luiz

Bom dia

Acho que seria assim:

cSql="SELECT '',v.cliente,c.razao,date_format(max(v.data),'%d/%m/%Y') as maiordata"
cSql+=" FROM vendas as v"
cSql+=" LEFT JOIN cliente as c on v.cliente = c.cod_client"
cSql+=" WHERE maiordata >"+Any2Sql(cGet[1])
cSql+=" GROUP BY v.cliente"
cSql+=" ORDER BY v.cliente"

Att

João Bosco

Link to comment
Share on other sites

Olá,

Use HAVING.

cSql="SELECT '',v.cliente,c.razao,date_format(max(v.data),'%d/%m/%Y') as maiordata"
cSql+=" FROM vendas as v"
cSql+=" LEFT JOIN cliente as c on v.cliente = c.cod_client"
cSql+=" GROUP BY v.cliente"
cSql+=" ORDER BY v.cliente"
cSql+=" HAVING maiordata < "+Any2Sql(cGet[1])

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...