Add variables with date field equal if possible by editing date column

Asked

Viewed 29 times

0

I have the following variables::

$v_data   = $row['DATA'];
$v_filial = $row['FILIAL'];
$v_chapa  = $row['CHAPA'];
$v_func   = $row['FUNCIONARIO'];
$v_dias   = $row['DIAS'];
$v_desc   = $row['DESCRICAO'];

They bring this:

DATA      FILIAL CHAPA  FUNCIONARIO    DIAS  DESCRICAO
10-04-2016  2    2311   JOAO DE SOUZA   7    TESTE
24-04-2016  2    2311   JOAO DE SOUZA   14   TESTE
08-05-2016  2    2311   JOAO DE SOUZA   14   TESTE
15-05-2016  2    2311   JOAO DE SOUZA   7    TESTE
05-06-2016  2    2311   JOAO DE SOUZA   21   TESTE
12-06-2016  2    2311   JOAO DE SOUZA   7    TESTE

What do I need: Where the dates are equal add the days column and if possible change the date column, example:

DATA      FILIAL CHAPA  FUNCIONARIO    DIAS  DESCRICAO
10-04-2016  2    2311   JOAO DE SOUZA   7    TESTE
24-04-2016  2    2311   JOAO DE SOUZA   14   TESTE

Expected result:

DATA      FILIAL CHAPA  FUNCIONARIO    DIAS  DESCRICAO  
  04         2    2311   JOAO DE SOUZA   21   TESTE

@Marllon Nasser, follow query:

SELECT 
       ifd_filial                  AS FILIAL,
       ifd_chapa                   AS CHAPA,
       ifd_nome                    AS NOME,
       DATE_FORMAT(ifd_dataa,'%m') AS MÊS,
       SUM(ifd_dias)               AS DIAS,
       ifd_desc                    AS DESCRICAO
       FROM 
            imp_folga_domingo 
            WHERE ifd_chapa = 2311
            GROUP BY ifd_dataa;
  • which bank? oracle?

  • Database: SQL SERVER .

  • Well, you have to make one group by for the month of the date... and make a sum of DIAS. That’s what you need to do.. I recommend doing it by query.. for php unfortunately I don’t know how to do it. But the solution is this.

  • @Marllonnasser brought to MYSQL I made the query no longer adding,could check if my syntax is correct ? I added the same question .

  • @otaciojb sum if the dates are equal or if the month of the date is equal?

  • 1

    @Virgilionovic Month

  • I saw what was wrong with @Virgil’s question.

  • @otaciojb Missed the group by on date... GROUP BY DATE_FORMAT(ifd_dataa,'%m');

  • @Marllonnasbe that way, vlw..

  • Got it !!! you want a solution SQL that @Marllonnasser seems to have solved, or you want a solution PHP ???

  • 1

    @Virgilionovic for me PHP would be better,more as I need to release I did with your help in sql even.

Show 6 more comments

1 answer

0


Final result:

 SELECT 
       ifd_filial                  AS FILIAL,
       ifd_chapa                   AS CHAPA,
       ifd_nome                    AS NOME,
       DATE_FORMAT(ifd_dataa,'%m') AS MÊS,
       SUM(ifd_dias)               AS DIAS,
       ifd_desc                    AS DESCRICAO
       FROM 
            imp_folga_domingo 
            WHERE  ifd_chapa = 2311
                   GROUP BY DATE_FORMAT(ifd_dataa,'%m');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.