Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Select em campo date agrupando por dia do mês


RRH

Question

Com o código abaixo consigo montar um relatório com o total de registros da tabela agrupado por bairros:

$sql = "SELECT bairro, COUNT(*) AS total FROM tabela GROUP BY bairro ORDER BY total DESC";

Ex:

BairroA -> 30

BairroB -> 42

BairroC -> 80

Como fazer uma consulta agrupando por dia do mês baseado em um campo date?

Ex:

Dia01 -> 45

Dia02 -> 60

Dia03 -> 33

Edited by RRH
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

RafaelSarti,

Como quero pegar o total de registros cadastros por dia do mês eu adaptei assim:

$sql = "SELECT data, COUNT(*) AS total, DAY(data) as dia FROM tabela GROUP BY dia ORDER BY total DESC";

Funcionou perfeitamente. Muito obrigado.

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
Answer this question...

×   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.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...