Posts by rLinhares • 7,797 points
331 posts
-
2
votes1
answer78
viewsA: Column ambiguous
Since you have many columns, the ideal way not to forget any field is to reference the columns of all fields; try the where thus: WHERE (m.mov_tipo = 'E') AND (m.mov_data >= '01/06/2018') AND…
-
3
votes2
answers426
viewsA: SQL command in String Mysql
Use the commands PREPARE and EXECUTE: PREPARE myquery FROM comando; EXECUTE myquery; You can search for more links like this. delimiter $$ create procedure eixos_caminhao (in numeroEixos int) begin…
-
4
votes1
answer131
viewsA: Column for Mysql row
An alternative is to divide the query into three subselects, one for each idquestion; the "problem" is that there will be several queries, in case the bank is too big, can get heavy. select `Roll…
-
0
votes1
answer43
viewsA: not in the same table
You need to check if the Customer has null contracts, the way you did is checking every table without specifying it: SELECT con_customer FROM con_contratos C1 WHERE NOT EXISTS (SELECT * FROM…
-
1
votes1
answer568
viewsA: Convert entire mysql database to lowercase
I don’t know any "simple" way to do this, but through this algorithm I believe that will have the expected result: SET @row_number := 0; INSERT INTO tabela_tmp SELECT (@row_number:=@row_number + 1)…
-
1
votes3
answers58
viewsA: Field referring to the MAX
You can control that in a sub-colony, where it’s ordered by datainclusao, loading only the latest: SELECT DISTINCT VEICULO, DATAINCLUSAO, REVISAO FROM PLANOS P1 WHERE P1.ID = (SELECT TOP 1 P2.ID…
-
0
votes2
answers55
viewsA: Doubt with group by - sql
I actually believe you can use a consultation like this: select distinct d.nome_departamento, p.descricao, p.valor from departamento d, produto p where p.id_departamento = d.id_departamento and…
-
0
votes3
answers1169
viewsA: Vector sum problem in C
The vector/array in C starts in 0; then you need your accountant loop also start in 0, since it is used as vector index: for (i = 0; i < 5; i++) { printf("Digite a sua nota da apol %d\n",i);…
-
2
votes1
answer136
viewsA: INSERT with Random SELECT
I added the clause FROM that was missing and I started to filter the Case_Number instead of ordering the result by it; see if the command below solves: db.Execute "INSERT INTO tbl_Sorteio SELECT TOP…
-
0
votes1
answer50
viewsA: Query with field as IN value
In the database you have something like 1,2,3,4 and you need to search for only one value, right? Really ideal would it not happen, you could have a relationship table to store the service id and…
-
-1
votes1
answer309
viewsA: Query with two sorts in descending order
Yes, it is possible. You just need to put the fields you want to sort in the sort command mysql: order by: SELECT * --campos que deseja retornar FROM nome_tabela WHERE num_contrato = @num_contrato…
-
2
votes3
answers367
viewsA: Returning(Null) when displaying a String variable
Are you declaring nome as being a char: char nome, sexo; There are two alternatives. The first is you declare the variable as a vector, where it will set the maximum length of characters it can…
-
3
votes1
answer66
viewsA: calculating date in update mysql
Use the DATE_ADD(): UPDATE contas SET baixa_valivade = true WHERE data_vencimento BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -5 MONTH) AND CURRENT_DATE() If the need is to update items with delay…
-
0
votes3
answers144
viewsA: Doubt - Array php return
In php, if you want to reference a position of a array nominal, should do as follows (considering its example): Array ( [0] => Array ( [nome] => Maria [idade] => 26 ) [1] => Array (…
-
1
votes3
answers134
viewsA: I’m having trouble summing up the column
Basically, in the group by should enter all fields that were not the sum: SELECT DISTINCT z.sales_office AS kam, z.customer, g.sales_order, d.nfnum, SUM(d.vlr_liq_nf) AS valor FROM TPL_GUARDA g LEFT…
-
-1
votes4
answers683
viewsA: Very slow SQL command
I edited the code in the question and I believe it became easier to understand. As it stands, there are several and and a or, then you’re probably having loop infinite in query. Try to use code like…
-
2
votes1
answer65
viewsA: 0097 - missing parentheses on the right. - Can help
In the where you are not closing the coalese. I believe the idea is to validate what is brought in select, then it would look like this: select distinct Coalesce(Sum(Case When…
-
6
votes1
answer499
viewsQ: COUNT(*) x COUNT(1) x COUNT(id)
I would like to understand better about the difference between these ways of using the counter: select COUNT(*) from tabela select COUNT(1) from tabela select COUNT(id) from tabela This question…
-
0
votes3
answers1210
viewsA: Select to bring the amount of certain records in related tables
The most complete and secure solution I could find was the following: declare @aux_col varchar(255) SELECT @aux_col = colaboradores FROM controles WHERE id = 1 --id do treinamento selecionado --…
-
0
votes2
answers1138
viewsA: SQL Syntax Error Exception: ORA-00928: SELECT keyword not found
I believe your problem lies in the creation syntax of Procedure. Take a look at that link talking about different ways to use a proc and tries to create like this: create procedure SP_INSERIRCLIENTE…
-
5
votes3
answers1003
viewsA: How to make a select within a condition?
SELECT * FROM tabela AS t WHERE (t.saldo = 0 AND EXISTS (SELECT 1 FROM tabela2 AS t2 WHERE t2.outracondicao = 'condicao')) -- OR t.saldo <> 0 When the balance is equal to zero, the search will…
-
2
votes2
answers336
viewsA: Foreach running only once
For identation your code should end after the var_dump: foreach($dados as $linha){ $linha = trim($linha); $valor = explode('|', $linha); var_dump($valor); But you don’t have the }; with this,…
-
6
votes2
answers1944
viewsQ: View or temporary table?
Analyzing a code problem I came across different approaches to similar problems where one has a view for data access, and another uses a temporary table. I searched and found this question which…
-
0
votes1
answer37
viewsA: How to join two results in a conditional query
If you already use the variable declaration structure, you will have no problem/constraints. The idea is to create a variable to concatenate the union (according to its validation) and then run:…
-
2
votes1
answer87
viewsA: SQL statement in Mysql with KURDATE(), does not display API result with PHP
The issue was resolved in a comment by @Milk, I’m answering just so the question has a "correct answer". The logic in assembling the select has been reversed; the correct form must be as follows:…
-
0
votes3
answers89
viewsA: problem with select case
You can turn this query into a subconsultation, grouping the return by fields that are not summations; thus, it will bring the end result to the user. select sum(finalizadas),…
-
4
votes1
answer7520
viewsA: Qt SQL - ERROR (42601): syntax error at or near
Error message shows syntax error in the query on the line cpf integer(11) NOT NULL UNIQUE; you are wanting a whole but are setting a size for it, which is not necessary. const QString sqlTable =…
-
2
votes2
answers738
viewsA: PHP SQL Inner Join - Show name instead of ID number
You just need to change the return field of your query; the junction between the tables seems to be being done in the correct way, so just return the description of guy and category instead of id:…
-
1
votes3
answers3659
viewsA: In Trigger we have INSERTED and DELETED. Why not "UPDATED"?
I found the question very curious and went to research. That link was what made the most sense to me. The idea here is to create a way to control the changed file(s) (s) (variable/table) and then…
-
1
votes2
answers34
viewsA: Adjust query sql according to available discipline
amended response after comments Using the via validation OR (since the control fields are of different tables), add also a validation in the field query; if it exists (Portuguese or math), calculate…
-
6
votes1
answer784
viewsA: Select the first row of each group in Mysql
I created a test fiddle and the reply given in comment by @Anthony Accioly meets what you need: SELECT MAX(item), grupo FROM tabela GROUP BY grupo edited: Considering the comments, I believe that…
-
2
votes1
answer74
viewsA: How to force use the float method instead of the double method?
You need to call the passing method floats by parameter, ex: float num1 = 1.1; float num2 = 2.2; Dividir(num1, num2); In case you already have the numbers and it’s not float, just give a cast: int…
-
0
votes1
answer130
viewsA: Make INNER JOIN on two different bases
Yes, it is possible; you just need to reference the banks to which the tables belong: $sql0 = "SELECT * FROM banco1.tabela INNER JOIN banco2.tabela ON banco2.tabela.id = banco1.tabela.id";…
-
3
votes2
answers490
viewsA: Using case in null field
Yes, you can. The parameter received (@parametro_boletim) will control whether the validation will be done with it equal to S or the N): SELECT * FROM tb_boletim WHERE boletim = @parametro_boletim…
-
1
votes1
answer106
viewsA: Correction of the Code in C
From what I understand is not displayed error, only the comparison logic is wrong. I suggest you create a variable to control whether or not the values are repeated; if not, display the message at…
-
2
votes2
answers1445
viewsQ: UPSERT or UPDATE-INSERT?
Across of that question felt the need to research and understand a little about the UPSERT. I was wondering What blessed command is that? I’ve never seen.. I found some information but it is not…
-
1
votes1
answer61
viewsA: Add float values from a Table
For your code the difference was only the toFixed in the exhibition, second that soen response: let result = 0; let columns = $("#tablepesquisaprodutos tr td:nth-child(" + 5 + ")"); columns.each(i…
javascriptanswered rLinhares 7,797 -
0
votes3
answers153
viewsA: Get the sum of authors' books with Mysql
Use the query below: select u.nome, sum(l.preco) from usuario u, livro l, carrinho_de_compras as c where c.id_user = u.id_user and c.id_livro = l.id_livro group by u.nome; I removed the Inner Join…
-
2
votes1
answer212
viewsA: IF condition - Good use practice
Apparently the way you structured is not the best. I say this because you do not use keys us ifs, which suggests they are only for what is being displayed in the code, i.e., validate whether the…
-
1
votes1
answer46
viewsA: Update of holidays in SQL Server table
That should solve your problem: UPDATE tabela_tempo SET IndFeriado = 'SIM' FROM DM_Tempo as tabela_tempo WHERE tabela_tempo.AnoRef IN (2017, 2018) AND tabela_tempo.IndFeriado = 'NÃO' AND…
-
2
votes3
answers529
viewsA: Difference between dates in months with decimal return
I started researching but couldn’t find a way to improve the accuracy of the Datediff via parameter, so I decided to leave for logic: declare @diferencaDias int, @meses int select @diferencaDias =…
-
2
votes1
answer476
viewsA: SELECT SQL WITH WHERE "DOUBLE"
The mistake is exactly what Ricardo pointed out in a comment; how is in the select, ESTE is syntax of a table column produtos, and such a column does not exist (says the error). Apparently you…
-
0
votes1
answer73
viewsA: Join SQL server
Considering only the code you passed, you can try the following query: sql = "SELECT * FROM configuracao b LEFT JOIN dividas a on b.registro = a.registro and a.empresa='" & LEFT(Combo1.Text, 2)…
-
4
votes1
answer57
viewsA: Error in SQL QUERY
By the syntax I believe you’re using mysql. So I believe you’ve forgotten the extract. SELECT COUNT(*) AS total FROM table GROUP BY EXTRACT(YEAR_MONTH FROM data) ORDER BY EXTRACT(YEAR_MONTH FROM…
-
1
votes1
answer2686
viewsA: How to make a SE function in SQL
In this case, the ideal is for you to use the CASE, since the return depends on the data validation of a specific field: SELECT CASE WHEN campo_genero = '1' THEN 'Masculino' ELSE 'Feminino' END FROM…
-
1
votes3
answers902
viewsA: RETURN THE SUM OF MAXIMUM 3 SQL VALUES
SELECT T.RECIPIENT AS NOME, SUM(T_TMP.AMOUNT) AS TOTAL FROM TRANSFERS T JOIN (SELECT TOP 3 T2.RECIPIENT, T2.AMOUNT FROM TRANSFERS T2 ORDER BY T2.AMOUNT DESC) AS T_TMP ON T.RECIPIENT =…
-
0
votes2
answers687
viewsA: TOTAL row with the SUM of columns using PIVOT
It is possible: SELECT ano AS Ano, CCUSTOS AS [Centro custos], coalesce([1], 0) janeiro, coalesce([2], 0) fevereiro, coalesce([3], 0) março, coalesce([4], 0) abril, coalesce([5], 0) maio,…
-
0
votes4
answers91
viewsA: Select with columns stating incorrect data
Try the code below: SELECT i.empresa, (SELECT top 1 j1.razaosocial from empresas j1 where j.id= j1.id) as j.razaosocial, i.exercicio, ( CASE WHEN c.lucrocontabil = 0 THEN c.lucrosimples WHEN…
-
0
votes2
answers533
viewsA: Query data from two different tables and list without merging data
If understood correctly, just join the two tables and give a order by desc. select * from tb_compras tc join tb_compras_pagamentos tcp on tc.id = tcp.id_compra order by tc.data desc detail: by the…
-
0
votes1
answer47
viewsA: Isnull get the next SQL condition
From what I understand you should check if the field is null before the conversion; then it would look like this: CONVERT(CHAR(08), ISNULL(C.PEDS_DAT_FAT, d.NFFE_DAT_ENT), 112) BETWEEN '20180501'…