Questions tagged as 'sql'

1
answer

Select checking for a condition

I need to do a select where a condition is checked. Ex: If the value of a given field is < 0 assigns the sum of this field the column " PerdaGerada " otherwise assign the column " LucroGerado ". Something like shown below: SE...
asked by 03.02.2016 / 13:19
1
answer

Update by changing one value by the other in the table

What update would you use to change one value for another in a table. A update in table produtos column cod_produto . I would like a query where in the table named produtos all that contain in the column...
asked by 19.09.2015 / 15:21
1
answer

"order by clauses" can create conflicts with each other?

Is it possible that if we have multiple clauses in order by , they are in conflict with each other? For example: select candidato.nome from candidato, perfil_oferta, prova_de_afericao where candidato.bi = prova_de_afericao.cod_prova and...
asked by 19.11.2015 / 18:15
3
answers

Get last auto increment PDO key

I have a problem with my system that looks like this, try { $sql = "SELECT Nid+1 AS Nid FROM noticias ORDER BY Nid DESC LIMIT 1"; $stmt = $DB->prepare($sql); $stmt->bindValue(":Nid", intval($_GET["Nid"])); $stmt->execute(); $results...
asked by 26.10.2015 / 17:21
1
answer

PostgreSQL syntax error using keys

I'm having trouble understanding why pgadmin is pointing to a syntax error in my query . select first_name, coalesce(to_char(avg(p.amount),'99.99'), 'nnn') valor_medio from { select c.first_name as nome_cliente, c.last_name...
asked by 22.12.2015 / 14:35
1
answer

Convert SQL script to Linq

I need to convert the SQL script below to Linq. SELECT [ID_Pessoa], [ID_ArquivoPagamento], SUM([Peculio_Valor]) AS 'Peculio_Valor' FROM [VW_PESSOA] WHERE [ID_Pessoa] = @ID_Pessoa AND [ID_ArquivoPagamento] = @ID_Arq...
asked by 08.12.2015 / 19:03
1
answer

Error connecting database with PDO

I have an OOP code in PHP, when I try to connect to the DB, the following error appears:    Notice: Undefined variable: operator in C: \ xampp \ htdocs \ StudentCount \ app.ado \ TCriteria.class.php on line 16       Notice: Undefined variabl...
asked by 05.09.2015 / 18:16
4
answers

Filter numbers not yet registered via SQL

I'm trying to find the numbers that have not yet been registered at the bank. I have a client table, in it I have the fields codigo and nome . When the user registers the client, he places the code manually, so he runs the ris...
asked by 29.05.2015 / 15:26
2
answers

ORDER BY WITH GROUP BY to get last row, sql

I am using this SQL code to pick up data, first it groups then it organizes by the birth date of rows . SELECT U.id, U.born_data, U.bold FROM users U GROUP BY U.bold ORDER BY U.born_data DESC In the meantime it does an inversion, it organ...
asked by 01.07.2015 / 16:17
2
answers

Trigger error

I'm making a system that moves cattle tracking and I'm having a question about creating triggers after update. The situation is this: in my bank there are several tables that have foreign keys to each other. Within these tables, there are the...
asked by 29.10.2016 / 23:13