Questions tagged as 'query'

1
answer

Select with when and case

I have the following select query: select F.nu_ine INE, to_char(D.dt_ficha, 'YYYYMM') as CMP, I.co_cbo_2002 CBO, CASE WHEN (B.tp_atend = 1 or B.tp_atend = 2 or B.tp_atend = 5) and I.co_cbo_2002 != '225142' THEN '0301010030' WHEN (B.tp_atend =...
asked by 09.11.2017 / 19:04
2
answers

Count function - Mysql

I have the following tables: times - time_id INT - time_nome VARCHAR rodadas - rod_id INT - rod_rodada INT - rod_pontos DECIMAL (10,2) - rod_fk_time INT I need to add punctuation and group by time.     
asked by 18.05.2017 / 19:09
1
answer

General error error: 1449 when searching MySQL Bank records

I'm getting the error below when doing SELECT: SELECT * FROM vn_horario_view;    SQLSTATE [HY000]: General error: 1449 The user specified as a definer ('root' @ 'localhost') does not exist How do I resolve this error?     
asked by 22.02.2017 / 20:00
1
answer

PostgreSQL - Inserting data into tables linked by Foreign Key

Hello I have a data insertion problem in tables linked by foreign keys. I have read in some places that there is a "with" command that helps in these situations, but I did not quite understand how it is used. I would like to put together f...
asked by 11.01.2017 / 06:30
3
answers

Conditional for record selection

I am having a question for selecting a record from a table and would like some help. An example of the structure of the following table: idhistorico_profissional | idprofessional | function | beginning | end | situation 9 77...
asked by 14.12.2016 / 01:43
1
answer

Query string works in Phpmyadmin and does not work in PHP

I have the following query that takes a date, has been tested in phpmyadmin and in the HeidiSQL program successfully: Query Mysql set @rn:=0,@grp:=0,@prevdate:=''; from (select DataEncomenda, @rn:=@rn+1 as rownum, @grp:=if(@prevdat...
asked by 01.12.2016 / 15:01
1
answer

Check difference between unlisted results and identify which day of the week is the date

I have the following query: SELECT V.CHAPA, F.NOME, V.DATA, MAX(V.SEQUENCIALBATIDA) AS BATIDA FROM ARELBATIDATRANSITOVIEW AS V LEFT JOIN V_DADOSFUNC AS F ON V.CHAPA = F.CHAPA WHERE...
asked by 19.10.2016 / 21:55
3
answers

Error using HAVING in query with date / time

I have the following query: SELECT ROW_NUMBER() OVER(ORDER BY V.DATA ASC) AS ID, V.CHAPA AS CHAPA, F.NOME AS NOME, V.DATA AS DATA, CASE WHEN V.BATIDA IS NULL THEN 0 ELSE V.BATIDA END AS IS_NULL FROM...
asked by 20.10.2016 / 20:44
2
answers

Limit 1 row in queries with primary key queries

One of the best practices for optimizing MySQL queries, dictated by an internet source, says that it is important to limit queries that already display only one row to one. For example, if I'm going to change a user's record, my current query...
asked by 26.08.2016 / 00:17
1
answer

SQL to know which last edited record

I have the following SQL: $dcadastroultimo = date("d.m.y"); $sqlidcidade = "select id, titulo, tipo from imoveis where cod = '$cliente' AND ueditado <= '$dcadastroultimo' ORDER BY id ASC"; I need you to list the last edited records, but...
asked by 15.03.2016 / 18:13