Most voted "query" questions
Query or *query* refers to the act of recovering data previously stored in a computerised system from certain parameters and/or filters, by means of a specific command or operator.
Learn more…1,160 questions
Sort by count of
-
0
votes2
answers838
viewsSelect picking up previous line
What I have to use in SQL SERVER 2008 to get the line before a certain enclosure. For example if in my Where below if the alert is = to 99 want to know the alert and the speed before the alert.…
-
0
votes1
answer36
viewsOracle - From/to Webfocus for Oracle
Guys, I’d like some help. I have an ETL that was created in Webfocus, and I will migrate it to Oracle. I’ve done a lot of/stops, and would like an alternative to the following situations. In…
-
0
votes1
answer79
viewsQuery with datiff returning 0 in sql server result
I have the following appointment: SELECT DATEDIFF(hh, MIN(BATIDA), MAX(BATIDA))AS HORAS FROM ARELBATIDATRANSITOVIEW WHERE CHAPA = 3187 AND BATIDA IS NOT NULL AND SEQUENCIALBATIDA IN (2,3) GROUP BY…
-
0
votes1
answer64
viewsSearching for data from an ID in DB
I did a search here and on google to see if it would solve my problem without having to ask a question, but I could not find any solution. What I am trying to do is create a "related" but without it…
-
0
votes1
answer32
viewsQuery to count how many fields equal to 0 a record has
I need to return how many fields equal to 0 each record has and rank the one with the most zeros down. Example: id | col2 | col3 | col4 1 | 1 | 0 | 0 2 | 0 | 0 | 0 3 | 0 | 1 | 4 4 | 0 | 3 | 5 5 | 3…
-
0
votes0
answers48
viewsQuery Performance - HELP
I’m making a query, but I am learning now. There is a way to improve the performance of this query? select a.COD_EMPRESA, b.Dat_pagamento from SAS_EMPRESA a full outer join SAS_ITEM_PAGO b on…
-
0
votes1
answer920
viewsDifference between hours without taking into account the date
Good night, I have the following code: WITH CONSULTA AS ( SELECT V.CHAPA, V.DATA, MAX(V.BATIDA) AS MAXBATIDA, MIN(V.BATIDA) AS MINBATIDA FROM ARELBATIDATRANSITOVIEW AS V WHERE V.CODCOLIGADA = 1 AND…
-
0
votes2
answers85
viewsChange column data
How can I change column data? I wanted to change some bits to false but I don’t know how. using (SqlCommand cmdadd = new SqlCommand("INSERT into Usuarios (Cadastro) VALUES (@Cadastro)",…
-
0
votes0
answers94
viewsSQL - AVG with vendor alias and grouping
I need to create a query that calculates the average of a vendor delivery "score". It follows query, and in sequence, explanation of the fields: SELECT distinct C7_FILIAL, CASE WHEN C7_FILIAL =…
-
0
votes1
answer512
viewsHow to do an INNER JOIN by bringing specific fields from two tables and removing the repeated records and with a max condition?
Well, I have the following tables: Table 01: And table 02: There I would like to bring only all fields with higher points and do not repeat the waiter in the case, how to do?…
-
0
votes1
answer39
viewsDoubt - Query SQL Server 2012
I have a query below that I need to bring inside the case only when the field Tarvencimento is less than today’s date (so far I managed to do), however, only when today’s date is 5° day after the…
-
0
votes2
answers2956
viewsError inserting Data into Mysql
I have this query to insert a data into the database: INSERT INTO `bancoTeste`.`TabelaTeste` (`t_id`,`t_label`, `t_parametro`, `t_valor`, `t_descricao`, `t_valores_padrao`, `t_tipo`) VALUES…
-
0
votes1
answer3485
viewsUpdate Multiple Columns
I have the following situation, I need to update the table SB1300 in the fields B1_DESC and B1_CODBAR for several lines. The Where will be the B1_XCODORI I can do it in the same query?…
-
0
votes1
answer118
viewsjQuery Function crashes after Ajax search
I made a system in Codeigniter that searches in real time. In my search, send the parameters via Ajax to the controller and do the query. I send all the HTML to a view. Then I take all the HTML from…
-
0
votes1
answer74
viewsHow to use aggregation functions in a WHERE?
I’m doing a college paper on databases, and one of the Query what I must do is this: Show all creditors who had a larger purchase total than that R$ 5000,00; I tried to: SELECT NomeCredor,…
-
0
votes1
answer91
viewsDoubt with select case
I have the following query: select f.no_equipe, i.no_cbo, count(b.tp_atend) from tb_equipe F, tb_cds_prof G, tb_cbo I, tb_cds_ficha_atend_individual D, tb_cds_atend_individual B where F.nu_ine =…
-
0
votes0
answers280
viewsError in MYSQL query
I have the following query select DISTINCT(p.id),g.id, p.slug, p.nome from game g join game_plataforma gp on g.id=gp.id_game join plataformas p on gp.id_plataforma=p.id group by g.id,p.id,p.slug,…
-
0
votes0
answers673
viewsChange data type varchar to int
Is there a problem changing the data type from varchar to int in mysql? I have a spreadsheet with some items that were inserted as varchar, all are numbers. The problem is that I need to do a search…
-
0
votes1
answer469
viewsWhat’s the difference between '(quotation marks) and '(quotation marks)?
Good guys, I want to know the difference of a value wrapped with '(quotation marks) and value without '(quotation marks). Ex: SELECT * FROM dados WHERE nome = $nome (valor sem uso das aspas) SELECT…
-
0
votes1
answer69
viewsDuvída in a Query that selects in two tables
Good afternoon, I am making a system of equipment scheduling, for better understanding I will put on topics some important information. Each schedule has a numbering of the equipment that will be…
-
0
votes1
answer166
viewsImproving Login Logic - JDBC - Javaweb
I am developing the method of login of an application, but I’ve been realizing that the query I’m running to check if a user is registered in the system and if his password matches the database data…
-
0
votes1
answer39
viewsDo not select records that have the status='Off' field
$query = "SELECT uf , count(*) as number FROM tab_clientes GROUP BY uf "; It is working perfectly but I have in the bank a status field that classifies the person as Off (need to continue registered…
-
0
votes1
answer28
viewsCheck codes that are not in the database with a query
I know I can check codes that are in one table and are not in another with the following query: SELECT cod FROM tabela1 WHERE cod NOT IN (SELECT cod FROM tabela2) But how can I check the records…
-
0
votes0
answers749
viewsHow to find out in SQL which is the primary key of the table?
I am learning SQL, and ran into the following problem: I need to know which of the columns is the primary key of the table. Have some command I can use in SELECT to get as return that information?…
-
0
votes1
answer181
viewsCreate query to return the smallest possible value
Good night. I need to do a sales report grouped by period and by card. But I do not know how to enter a store and horizontally of it appear the values of each card. Example of how the output should…
-
0
votes1
answer96
viewsChunk on Laravel 4.2 using lots of memory
I am using in an application a query to get data from a table and then generate a file xlsx. The problem is that it returns a lot of information, about 1,5 GB. As a solution, so I’m using the method…
-
0
votes1
answer50
viewsHelp for designing mysql query
I have the following table in Mysql: Cod,D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13,D14,D15 D1...D15 fields are filled with values between 1 and 25 in each record. There is no repetition of values…
-
0
votes0
answers338
viewsJoin querys using Outer apply
I have these three querys, and I want to put them together using the outer apply. How can I do that? SELECT SR1.COMPANY, SR1.FILIAL, SR1.DOC, SR1.SERIE, SR1.LOCAL, SR1.TIPONF, SR1.CLIFOR,…
-
0
votes1
answer1658
viewsRemove the last value found inside a string
I need to take an average of payment conditions in the database and I came across the situation where the condition column is a string and it can receive parcel values separated by bar. I need to…
-
0
votes2
answers322
viewsFind lines of the last 24 hours that repeat the most (Mysql)
'SELECT `from`, `to`, count(*) AS num_clicks FROM my_rank WHERE my_rank_data BETWEEN "'.$yesterday.'" AND "'.$today.'" ORDER BY num_clicks DESC LIMIT 0,20'; Above I am trying to take the fields…
-
0
votes1
answer65
viewsQuery with SQL Server query
I have the following query in SQL Server, to return me a list of cities I need. select IDCidade as "ID", case UF when 'RS' then '1' when 'SC' then '2' when 'PR' then '3' when 'SP' then '4' when 'RJ'…
sql database sql-server query sql-server-2012asked 7 years, 11 months ago Luís Felipe Dal Molin 169 -
0
votes2
answers2415
viewsSQL query that compares two tables and returns values
Work with a database using with DBMS Postgresql, where I need to compare tables, example: table_janeiro and table_February. I need to perform two consultations... first You must return the values…
-
0
votes3
answers252
viewsReturn the row of a table when the value of Count(field) is 0 in Mysql
I need that even when the search does not generate results, is displayed the value 0, I tried with the following SQL search, but without success: SELECT c.categoria as categoria, CASE WHEN…
-
0
votes1
answer492
viewsMongodb: Projection of only one element from one nested array to another nested array to one object
I have the following situation: I need to query a document with a projection that returns only the first element of a list. Only this list is inside another list, and that other list is inside an…
-
0
votes1
answer80
viewsGrouping of lines Group By
I have the following appointment: SELECT distinct CAPA.COD_HOLDING, CAPA.COD_MATRIZ, CAPA.COD_FILIAL, CAPA.ID_NF_ENTRADA, CAPA.NUM_NF, CAPA.DT_ENTRADA, CAPA.DT_EMISSAO, CAPA.COD_CLIFOR, CAPA.COD_UF,…
-
0
votes1
answer56
views -
0
votes1
answer264
viewsDatabase column named with alias not found in WHERE clause
I have this SQL query where I need to name a column twice datareferencia for anobase and mesbase, as follows example. But column error not found is shown. In my view, after I apply the alias the…
-
0
votes1
answer43
viewsPostgresql: Catch amount of errors and hits
I need a query to get amount of errors and hits from this table.…
-
0
votes2
answers124
viewsChartjs + mysql + php (month entries)
Guys, I have a user registration table. I am creating a chartjs to show on a bar chart the number of registered users per month. The mysql query would only have to return me 2 columns (MONTH AND…
-
0
votes1
answer45
viewsHow to shrink a large query - Postgresql
In Visual Studio, we have the possibility to shrink a large code, IE, visually decrease the size, as a way to facilitate reading, example: #region Seu código aqui... #endregion I would like to do…
-
0
votes2
answers98
viewsSelect data from three SQL tables
I am trying to join data from three tables using this sql: SELECT cod_nota, cupom, valor_contrato, valor_cadastro, data_emissao FROM cupons_nota, vendas, notas_fiscais WHERE cupons_nota.cupom =…
-
0
votes1
answer544
viewsHow to optimize a select within an update?
I created a stored-Procedure which updates the Drive table balances. At first I tried to use From Movimentacao within the update of the drive, only that returned error. I fixed this problem by…
-
0
votes0
answers58
viewsComparing three column records in a mysql table
I make an appointment at COL1 which has the total of lines and then make an appointment at COL2, but it is smaller than COL1. How do I make COL2 return me the Ids equal to those of COL1 so that they…
-
0
votes0
answers59
viewsCode is not sending data to the database
This first code for registration is not working, it is equal to another that is working that registers users, is giving error in $insert name and display the message Unable to enter record:, I tried…
-
0
votes1
answer47
viewsIsnull get the next SQL condition
how can I do on SQL server a condition if the return of a field is null and it returns another condition ISNULL( CONVERT(CHAR(08),C.PEDS_DAT_FAT,112), d.NFFE_DAT_ENT) BETWEEN '20180501' AND…
-
0
votes1
answer91
viewsdata field with direct order by in mysql displays a result and php exits differently
I’m trying to display a query ordered by month field date, in the phpmyadmin the query comes out right and when I display the result of the same query with php the date comes out of the correct…
-
0
votes0
answers191
viewsHow to debug a Mysql query?
Is there any way to know what’s wrong with this QUERY? When you perform a query, it displays it on the screen but nothing appears, the var_dump returns NULL, what steps a professional takes to know…
-
0
votes2
answers652
viewsConvert SQL query to Mongodb
I have little (or no) knowledge in non-relational banks. I need to convert the below query (Sqlite) into an equivalent query to be executed in Mongodb. SELECT COUNT(*) FROM match_table WHERE…
-
0
votes0
answers35
viewsPHP query with response from another query
I run a query that returns me a list of Ids. With each ID of this list I want to do an Insert in a second table. My code: <?php $db = mysqli_connect("localhost","root","","test") or die("Erro ao…
-
0
votes0
answers918
viewsShow result grid in mysql Workbench
When running queries on my MYSQL Workbench, I cannot see the Result Grid, only the output screen saying whether there was an error while executing the command or not. How can I activate the Result…