Posts by bruno • 7,237 points
193 posts
-
0
votes2
answers57
views -
1
votes1
answer248
viewsA: USING PIVOT ORACLE
This behavior is caused by the use of GROUP BY in the sub-query. The way it is being used has a behavior similar to the use of the DISTINCT predicate. Its sub-query is returning Ana DEC 123 7 2016…
-
1
votes2
answers99
viewsA: Group by mysql adding null values
Unless there is at least one record in your table for each of the cases listed, how you approach your problem will not produce the desired result. In this particular case, COALESCE will not help. In…
-
4
votes2
answers3449
viewsA: Get only last query sql server record
There are several alternatives, I will leave here one that makes use of the "window function" ROW_NUMBER. ;WITH cte AS ( SELECT EMPRESA, CODIGO, DTINICIO AS INICIO, DTFINAL AS FINAL, ROW_NUMBER()…
-
1
votes2
answers484
viewsA: Incorrect syntax error next to engine
The IDENTITY(1,1) statement is not valid for Mysql (it is a valid statement for SQL Server). The equivalent for Mysql is AUTO_INCREMENT CREATE TABLE SITE ( SITE_ID INT NOT NULL PRIMARY KEY,…
-
2
votes1
answer836
viewsA: SQL Server Composite Key
Your query to identify duplicate records is correct. There is however another alternative that usually has better performance: The use of ROW_NUMBER(). To remove duplicate records, ensuring that the…
-
0
votes2
answers183
viewsA: Select in Sql Server
There are several alternatives to get the desired result. Here are three alternatives. The first using a "Function window": SELECT * FROM ( SELECT Version, LastChanged, ROW_NUMBER() OVER (ORDER BY…
-
1
votes2
answers3778
viewsA: Return the shortest date within Select
You can simply change your GROUP BY, removing the column data, and change the SELECT clause by applying the MIN aggregation function. This will ensure that for each nCRM only the older date will be…
-
3
votes3
answers200
viewsA: List columns according to current date
The best would be to review the data model but, if you really want to proceed, here is an option: SET @DiaHoje := DAY(CURDATE()); SELECT CONCAT('SELECT nome, ', GROUP_CONCAT(CONCAT('`',…
-
4
votes2
answers2062
viewsA: How to exclude white spaces
You can use a regular expression: System.out.println(" texto com espaços em branco".replaceAll("\\s+", " ")); Upshot text with white spaces To also remove the spaces at the ends, you can first apply…
-
3
votes2
answers42
viewsA: IN() order in mysql
You can use the operator FIELD SELECT * FROM pedidos WHERE id IN (1,3,4,2) ORDER BY FIELD(id, 1, 3, 4, 2) The operator operates as follows: FIELD() devolve a posição de um determinado valor (caso…
-
3
votes3
answers160
views -
0
votes1
answer54
viewsA: Máquina Dobradora
You have two options: Creates a loop/loop and asks the user to enter a value for each iteration and stores it directly in the array; or Asks the user to type the values in a single line, separated…
-
0
votes4
answers744
viewsA: How to validate if Textfield is empty?
Your code is comparing the objecto textFiel with the empty string (""). What you want, is to compare if the property text of the textFiel object contains or does not contain any text. This can be…
-
1
votes1
answer42
viewsA: Find SQL values
The idea is there, but the syntax is not completely correct. An alternative would be like this: SELECT nomeprod, valorvenda FROM tabelaproduto WHERE nomeprod LIKE '%A%' AND estoqueprod BETWEEN 20…
-
1
votes2
answers1212
viewsA: Figure out which column would be truncated (date would be truncated)
Of the many requests to the team responsible for MS SQL Server from the user community, this should be at the top of the list. Here is just one example: Please fix the "String or Binary data would…
-
1
votes1
answer1039
viewsA: SQL query with SUM, displaying the return in rows
I will assume the existence of a table containing numerical values: CREATE TABLE #Tabela ( Codigo INT, Montante FLOAT, ) INSERT INTO #Tabela(Codigo, Montante)VALUES (1, 4), (1, 2), (2, 6), (2, 1),…
-
2
votes1
answer967
viewsA: Sql server turn a column into multiple rows
No cursor needed. A possible solution may be the following: CREATE TABLE #Livros ( Codigo INT, Nome NVARCHAR(25), Capitulos INT, ) INSERT INTO #Livros(Codigo, Nome, Capitulos)VALUES (32, 'Jonas', 4)…
-
13
votes2
answers1527
viewsA: How to search for saved records in the current week?
I would suggest the use of function YEARWEEK() SELECT * FROM tblVacina WHERE YEARWEEK(data_criacao, 1) = YEARWEEK(CURDATE(), 1) (I’m trying to create Sqlfiddle but I can’t execute)…
-
0
votes1
answer28
viewsA: Qdateedit component only accepts dates from 1752
By default the class Qdateedit accepts dates in the range 14 September 1752 until 31 December 7999. However, this range can be changed by simply using the method setMinimumDate(const Qdate &min)…
-
1
votes2
answers1081
viewsA: Run SELECT within a CASE
The question already has an answer in the comments, but here is an answer if someone comes across the same question in the future SELECT Cup.id, Cup.nome_cupom, Cup.valor_cupom, Cli.id_cliente FROM…
-
0
votes2
answers142
viewsA: How to bring date without Sql server 2008 record
A solution is to create an auxiliary structure with the date range for which you want to generate the results. If you want to use this solution, you have several alternatives (the list is not…
sql-serveranswered bruno 7,237 -
1
votes2
answers706
viewsA: Inform a date, and catch the interval of the week of the month of that date (from Sunday to Saturday)
A solution for Mysql is to use the functions DAYOFWEEK and DATEADD, for example: SELECT ADDDATE('2016-05-05', INTERVAL 1 - DAYOFWEEK('2016-05-05') DAY) Domingo ,ADDDATE('2016-05-05', INTERVAL 7 -…
-
1
votes2
answers8408
viewsA: How to concatenate the results of a RELATION into a SELECT?
Here’s a solution using FOR XML with PATH mode SELECT DISTINCT C.ID, SUBSTRING(( SELECT ', ' + P.NOME FROM dbo.Produtos P WHERE P.FK_CATEGORIA = C.ID FOR XML PATH ('') ), 2, 1000) TODOS_OS_PRODUTOS…
-
1
votes1
answer227
viewsA: Group SQL values by two fields
You can do it like this SELECT CASE WHEN IDADE <= 12 THEN '0-12' WHEN IDADE BETWEEN 13 AND 65 THEN '13-65' WHEN IDADE > 65 THEN '66 ou mais' END AS FaixaEtaria, ESCOLARIDADE, COUNT(DISTINCT…
-
1
votes1
answer114
viewsA: Count the height and width of an "image" (char* using n) - C++
Suggested the use of std::string instead of char *, whenever possible. You can create your own generic function to separate a std::string of data a delimiter. Here is an example using only Std…
-
4
votes1
answer1998
viewsA: Doubt how to display binary tree by width?
What you want, as the name of your function indicates, can be obtained using the traverse algorithm Breadth-first search (BFS) or Search in Width To the following binary tree 15 / \ 6 20 / \ \ 3 7…
-
4
votes1
answer12863
viewsA: Return to code start after a C if or switch case
You can use a do-while. Until a valid option is entered the program will continue to ask for user input. #include <stdio.h> int main(void) { char op; do { printf("Digite algo\n 0 - Sair\n 1 -…
-
2
votes1
answer98
viewsA: Help with SQL to find planes that have already done all routes
Try it like this: select a.matricula from aviao a left join ( select matricula, count(distinct cod_rota) numRotas from voo group by matricula ) v on v.matricula = a.matricula where v.matricula is…
-
1
votes1
answer1228
viewsA: QT Creator - How to open a window with directories for the user to select text file ? C++
I suggested the use of class Qfiledialog. This class provides a dialog box that allows the user to choose a file or directory. Here is a small example: #include <QApplication> #include…
-
2
votes1
answer191
viewsA: How to get really random numbers with 'Rand()' in C?
You’re most likely not initializing the seed to generate the pseudo-random numbers. As this is only for school work the most common way to generate random numbers in C should be sufficient. You can…
-
4
votes1
answer251
views -
3
votes1
answer200
viewsA: doubt about exiber values and decrypt in the Chained Queue?
The stack is a data structure that provides the following operations: push (enqueue) - Inserir um elemento no final (tail) da fila pop (dequeue) - Remove um elemento do inicio (head) de uma fila não…
-
2
votes1
answer151
viewsA: Error in Trigger Sqlite
Your Rigger displays some syntax errors. Here is an alternative CREATE TRIGGER TGmovimentacao AFTER INSERT ON manutencao WHEN NEW.tpMov = 'S' BEGIN UPDATE Remedio SET Remedio.RemedioDose =…
-
0
votes2
answers8499
viewsA: Subselect in Oracle bank
An alternative would be select t01.teste from teste t01 inner join ( select isn_teste, min(isn_pessoa) isn_pessoa from tes_teste group by isn_teste ) t04 on t04.isn_teste = t01.isn_teste left join…
-
1
votes1
answer234
viewsA: List the last record of a table field
You need to change your query to get the destination_id corresponding to the most recent date. This can be done as follows: select registration, destination_id from reports r inner join ( select…
-
8
votes1
answer2438
viewsA: A break within two for actually works as a continue?
First, the difference between the break and the continue: The continue jumps to the next cycle iteration. That is, just ignore the rest of the instruction block of an iteration. The break forces the…
-
2
votes2
answers907
viewsA: Mount Stored Procedure Dynamic Query in SQL Server
A solution would be: USE [MarcenariaDigital] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE uspTeste @fornecedorId int, @marcaId int, @corId int, @descricao varchar(50) AS…
-
1
votes3
answers131
viewsA: Bucket Sort + Thread
The definition of the function pthread_create is int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); As you can see by the definition, the…
-
2
votes1
answer1326
viewsA: How to deal with the use of getline() in a for(;)?
A possible solution passes, as you presented in your question, by the use of the function getline. The replacement in this case is almost immediate. You just have to ensure that the buffer cin is…
-
4
votes1
answer503
viewsA: Program to filter odd numbers in a number list
The error is in the way you use the operator mod. Set your function to impares [] = [] impares (x:xs) | x `mod` 2 == 0 = impares xs | otherwise = x:(impares xs) Or if you want to use prefix notation…
-
3
votes2
answers109
viewsA: Unix and linux are reserved words?
Not reserved words but predefined macros when the compiler is running on a Linux/Unix environment. Try, on the command line, to run the following command to list all these macros: gcc -dM <…
-
1
votes1
answer40
viewsA: Question about query (grouping)
Assuming the following structure create table aluno_legado ( ra varchar(03), disciplina int, conceito varchar(01) ); insert into aluno_legado(ra, disciplina, conceito) values ('ra1', 1, 'R'),…
sql-serveranswered bruno 7,237 -
1
votes1
answer658
viewsA: Is it possible to pass string from string class as pointer to function?
I assume you’re asking if it’s possible to move to a function, a pointer to an Std:string. Yes, it is possible. The function signature would be, for example: int funcao(std::string *str) However, as…
-
4
votes2
answers10606
viewsA: Ways to instantiate an object and declare constructors
There are some minor nuances left to explain, so I leave here some comments. For your example using namespace std; class Carro { private: string modelo; string marca; public: Carro(){} Carro(string…
-
3
votes1
answer6731
viewsA: Compare Current Line to Previous
An alternative using only ROW_NUMBER for those still using SQL Server 2008. For the following table CREATE TABLE Teste(id CHAR(02), cod INT, valor INT, data DATE); INSERT INTO Teste(id, cod, valor,…
-
0
votes2
answers98
viewsA: SSH on Linux Using Ubuntu
First of all, I would suggest that you not use user authentication/password for security reasons. Key authentication should be the preferred method. Now, to answer your question, you can use a block…
-
6
votes4
answers1166
viewsA: How to sort the data of a query by predefined values?
Yeah, you can do something like that: SELECT * FROM usuarios INNER JOIN estados ON estados.id = usuarios.estado_id ORDER BY CASE WHEN estados.nome = $valor THEN 1 ELSE 2 END, estados.nome The logic…
-
2
votes1
answer873
viewsA: do Sort of a file with multiple columns
You can use the option -V (--version-sort) of command sort to obtain the desired output. Of the manual: -V, --version-sort natural sort of (version) numbers within text Assuming your file has a name…
-
2
votes2
answers2125
viewsA: Copy (cp) to current folder on LINUX
It is possible to exempt destination path when giving a command to copy (cp) on the linux console for the current/current folder? Yes, it’s possible and it’s quite simple. The current directory can…