Most voted "sql" questions
Structured Query Language (SQL) is a language to query databases. Questions should include examples of table code and structure. This tag refers to the default language, not to be used for questions about the implementation of specific DBMS (such as Mysql, Postgresql, Oracle, MS SQL Server). In this case use the specific DBMS tag. Answers to questions marked with ANSI SQL should use SQL as much as possible.
Learn more…6,771 questions
Sort by count of
-
1
votes1
answer51
viewsAdd up the total quantity of a product with different batch? SQL ORACLE
Hello! How are you? I hope everyone is well! Guys I’m new in the business and I believe my problem is easy to solve, but I still have no knowledge to solve and from now I thank everyone for the…
-
1
votes0
answers48
viewsADD CONSTRAINT USING INDEX LOCAL
I have a table signed by DATA_HORA and I would like to create CONSTRAINT forcing the use of INDEX LOCAL instead of GLOBAL, but I am facing the following error. That’s possible? Relatório de erros -…
-
1
votes1
answer51
viewsAdd separate lines of a child table with values of a parent table without duplicating the values of the parent table
There is a SALE table that generated 2 records in the DOCUMENT table I needed to show the total sum of value fields of these two lines (showing row by row), but they need to add with some value…
-
1
votes1
answer63
viewsSQL doubt in query
Can someone give me some guidance in this consultation? How to find out how many possible shows watched? For viewers of the day "24/07/2020" who passed the turnstile before the opening time of the…
-
1
votes2
answers141
viewsProcedure with CASE in the WHERE clause
Well my doubt is this, I’m beginner in sql serves, i am running a trial and in it using the CASE method the following code shows what I am doing: ALTER PROCEDURE [dbo].[STP_S_Cliente_Busca]( @Busca…
-
1
votes1
answer103
viewsHow to search for data from one column in another column in SAS using Proc-SQL?
I need to perform a query in which I have to do a Join between two Tables. The column I should use to do the "On" of Join is the CPF/CNPJ. However, table A’s CNPJ data is only with 12 numbers, while…
-
1
votes1
answer31
viewsConvert percentage
I’m having trouble converting % my code: select veiculos , qtd , trunc(qtd / sum(qtd) over()* 100, 4 ) PERC from ( select ent_datahora_entrada , veiculos , count(*) qtd from ( select…
-
1
votes0
answers46
viewsDoubt Beginner WHERE EXISTS
I’m a beginner in the SQL world, I’m learning some functions and I came across a problem where I can’t understand. I have a table medico with the attribute cod_medico. In that attribute is the…
-
1
votes1
answer67
viewsHow to override the Laravel Illuminate Database Connection.php run method?
I need to customize the callback function call in the run() method of the Connection.php class, located in the frameword Laravel src Illuminate Database Connection.php The problem is that it is in…
-
1
votes1
answer21
viewsHow to select records that have no relationship between 3 tables
Assuming I have 3 tables: Company, Users and Users (which relates the other two tables) Enterprise +----+----------+--+ | ID | NOME | | +----+----------+--+ | 1 | Empresa1 | | | 2 | Empresa2 | | | 3…
sqlasked 3 years, 11 months ago Lucas Ferreira 33 -
1
votes1
answer36
viewsHow do I make a Total Current?
I have a Query made that takes all the invoices of a specific client and it appears all the payment information and current balance, as shown in the excel image: Img1 The idea is to add the missing…
-
1
votes2
answers82
viewsGroup closer values in Postgresql
Good morning, you guys. I have a question regarding a grouping of data in postgresql and I would like to know if you can help me. I have a database containing a table with entry times in an…
-
1
votes1
answer59
viewsWhen I run my SQL function it returns NULL, even with data entered in the database
I created an SQL function to calculate the user’s daily calories by multiplying their baseline metabolic rate by the level of physical activity. Workbench shows no error when implementing my…
-
1
votes1
answer35
viewsFilter search for only ID’s that have more than one POSTGRESQL linked record
In the query below I can find the largest reduced linked to account, but I need it to be only in the id’s that have more than one reduced linked. The table has more than 4000 reduced SELECT (id,…
-
1
votes0
answers315
viewsHow to send images in a Fastreport report with Delphi?
I was having a lot of doubts about that. I searched several articles about it over the course of days, but in all of them I saw a flaw, most did not clearly show how to send a parameter or variable…
-
1
votes0
answers21
viewsAdd column values created in PIVOT
Well, in this query I have to list the products that went out for consumption in a certain period, and how much was consumed of each product. I have the Cód of the product, name, date of movement,…
-
1
votes1
answer106
viewsseparate records from field with point and comma separated values in Mysql
I have two tables in mysql database, GROUPS table and PRODUCTS table. GROUPS +-----------------+ | grupoid | +-----------------+ | 1 | | 2 | | 3 | +-----------------+ PRODUCTS +-----------------+ |…
-
1
votes2
answers47
viewssql search filter - exception
Hello! I’m having a hard time developing a logic for a bank search. I need to return from the bank a table with the student list enrolled with a certain type of voucher. But each student can have N…
-
1
votes0
answers31
viewsPercentage in Procedure SQL
Good morning, you guys, I need to create a rule within a precedent, where I first need to get 100% of the ids marked with AP. And then of these 100%, I need to get 15% of the status ids = 10. But I…
-
1
votes1
answer33
viewsPerform a query by checking if this record already exists in another table
The logic is as follows, I have a table "TBL_NOTICIAS" and another table with name "TBL_DESBLOQUEADO". When the user accesses the page I present all the news and he can unlock the news you want to…
-
1
votes0
answers35
viewsUse SQL output to insert into another table
What I’m trying to do is this: Make a search in a table, if you find the result. With the search result, insert the result in another table. I am developing in Nodejs, at first I imagine that I need…
-
1
votes0
answers35
viewsCopy tables to another bank while maintaining relationships
I’m trying to send some records from one bank (bank A) to another (bank B) that contains the same structure. They are records of 3 tables, 1 table(patient) contains MAIN records and the other 2(file…
-
1
votes0
answers27
viewsDuplicate entry '78161' for key 'PRIMARY' (Not duplicated)
I have a table that stores people’s data and when I give an input to add a new record it says that the 'id' (primary key) is duplicated, however it is not duplicated. The table where I am entering…
-
1
votes1
answer32
viewsRecover Milliseconds of a date recorded in an MSSQL Server 2019 BD with VB.Net + ADO.Net
I would like to know how to recover a date as given from the recorded Milliseconds in a MS SQL Server 2019 database using VB.Net + ADO.Net. Whenever I try to rescue the date, comes in the fomrmato…
-
1
votes0
answers28
viewsupdate sql function + php not working properly
i needed to do something very basic, I am creating a customer site and I need to create the function of decreasing in 1 the client portion in db, follows below the function that I set up function…
-
1
votes0
answers43
viewsSelect data in three Mysql tables and bring the latest result with the sum
I am trying to join data from three tables using this sql: select c.NOME,c.CPF,e.DATA_CAD ,e.ENFERECO as ENDEREÇO_Atual , sum(f.VALOR) from cli1 as c inner join end1 as e on c.IDCLI1 = e.ID_END…
-
1
votes2
answers74
viewsDúvida Postgresql
Good morning. I have the following SQL working: Select g.galeria,g.tipo,g.finalidade,count(p.galeria) as total from pessoas p full join galerias g on p.galeria = g.galeria group by…
-
1
votes0
answers140
viewsDBCC CHECKDB Cannot continue the Execution because the Session is in the Kill state
In our current database scenario, we have two databases A main database: BANCO01 And a BANCO01 dependency database used for testing: BANCO02 After running the database integrity check script. DBCC…
-
1
votes1
answer58
viewsHow to count the amount of distinct occurrences in a BD and return
I have 3 tables in a library database. One is the member table, with the age of that member and one PRIMARY KEY. The second table, book, has a PRIMARY KEY isbn and the rest of the attributes authors…
-
1
votes2
answers68
viewsSum of a product returning in a column the total
Sum of a product returning in a column the total Guys good night, I wonder how I can make a SELECT that returns exactly the same as what is below (I modified in F12 to see if you can understand…
-
1
votes0
answers34
viewsDoubt with JOINS and GROUP BY in an SQL (Access) query
Thanks for your help. I am not very advanced in SQL and I am facing a difficulty here, is the following: SELECT tbl_afs_pregao.numaf, tbl_items_pregao.nomeitem, Sum(tbl_items_af.qtd) AS SomaDeQtd,…
-
1
votes1
answer58
viewsSQL does not calculate with NULL values
I have a query where I have 3 columns grouped and last totaling 3, the problem is for Edson the query is not TOTALING. TOTAL = CREDIT - (DISCOUNT + REBATES) The total Edson has to give 266,49 but my…
-
1
votes0
answers16
viewsSearch for lack of ID in two WOOCOMMERCE tables
I need to search and return todos os pedidos who are in status processando, and who possess the column meta_value in vazio or inexistente in another table. 1º - In wordpress, I will check all…
-
1
votes0
answers48
viewsSQL Join with typeorm
Look at this, I have the following structure of entities: Entity/Ticket.ts import {Entity, PrimaryColumn, Column, OneToMany, ManyToOne, OneToOne, JoinColumn} from "typeorm"; import { Academia } from…
-
1
votes1
answer35
viewsGroup by records by date and user id
Good afternoon! I have a table like this: I need to perform a SELECT that counts how many records I have per month and year, but grouping together the "repeated" records...(Records repeated in this…
-
1
votes1
answer99
viewsWhere in a select on a system using a many relationship type for many
I’m making a basic system that has a table of projects, one of tags and a pivot table, project_tag. Each project has a id, title and a tag. The table of tags has a id and a title . The table…
-
1
votes1
answer32
viewsReturn the period where you have the highest number of records in a table
I am mounting a query from the same table of my bank that needs to return (as stated in the title) the period (monthly, for example) in which presents the largest number of entries. It turns out…
-
1
votes0
answers25
viewsHow to use EF Core Code First in Azure Synapse
I’m trying to use migrations to manage database schemas with Entity Framework Core and C# in Azure Synapse, when I run the update-database command I get an error message as described below: Enforced…
sql entity-framework windows-azure entity-framework-core azure-synapseasked 3 years, 7 months ago Carlos Lemos 324 -
1
votes0
answers38
viewsWhere am I missing? A code that tries to recover data from an Access database with VB.NET
Good night, My name is Lucas and may you help me with the following doubt. I have a Windows Form in visual studio where I have a button that executes the code below. It reads an X value in the…
-
1
votes1
answer22
viewsAdding Amount of Input per month and customer
Hi, I can’t add up the amount of incoming products per customer per month. Can anyone help me with any tips? I’m getting the following result: MÊS Quantidade 1 95 1 55 2 90 3 140 3 40 3 95 3 40…
-
1
votes0
answers38
viewsAlways Encrypted: How to insert in encrypted column?
First I tried it: DECLARE @test varchar(50) = 'test' insert into Customer values ('Lucas', 'Test', @test) But you made that mistake: Encryption scheme mismatch for columns/variables '@test'. The…
-
1
votes1
answer54
viewsINNER JOIN sql query with GROUP BY
I have a select that is giving error. The idea is the result show five columns (CODPROD, DESCRPROD, CODLOCAL, DESCRLOCAL, STOCK). I’m extracting four tables (TGFEST, TGFPRO, TGFLOC and TGFGRU) and…
-
1
votes0
answers26
viewsEncoding error when running script
well, I’m trying to run the script this way: psql -U [usuario] -d [banco] -f [script] and in the cmd appears like this: DROP TABLE CREATE TABLE COMMENT COMMENT psql:pais.sql:282: ERROR: character…
-
1
votes2
answers60
viewsSQL Server Questions When Adding Shift 3 (SUM)
How to make a sum (SUM) of shift 3 of a company and organize per day? The problem is that shift 3 ends the next day (it starts at 10 pm and ends at 6 pm the next day), so I am trying to make an…
-
1
votes1
answer44
viewsHow to select data that depends on other tables that have another key in common?
Hello! I was working on a database project using the SQL language in Mysql Workbench. The setting of my project is a university library where we have the tables: (Bold = PK | Italic = FK)…
-
1
votes0
answers27
viewsQuery pass null parameter, bringing all values
Hello, I have a query in which I need you to bring me or the value passed in the parameter or, if no value is given, bring all information that is not null: Example select cd_medicamento,…
-
1
votes2
answers49
viewsSQL - WHERE using 2 conditions and AND as conditional - Answer is not the expected result
Good afternoon, doubt is very basic. I am counting items from a single table to two specific "classes" (M and N) within the same column (two possible outputs is what I am calling a "class"). When I…
-
1
votes0
answers23
viewsPassing Datatable to a table-Valued Parameter in a stored SQL file does not work
I’m creating a revenue website. On my Masterpage (I am working on ASP.net), I have a search icon and when the user clicks on that icon, I will read three checkboxlists and pass the selected values…
-
1
votes2
answers90
viewsI need to create a report that sums up values by category and groups this information according to origin
I need to create a report that sums up values by category and groups that information according to origin. I explain: I need to bring the sum of monthly fees, enrollment, material and fees, but…
-
1
votes0
answers20
viewsQuestions with JOIN [solved]
CREATE TABLE CIDADE( ID_CIDADE INT NOT NULL, NOME VARCHAR(50), CONSTRAINT PK_FORNECEDOR PRIMARY KEY (ID_CIDADE) ); CREATE TABLE FORNECEDOR( CNPJ CHAR(14) NOT NULL, RAZÃO_SOCIAL VARCHAR(40), ENDEREÇO…