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
-
0
votes1
answer73
viewsCalculate Average by SQL SERVER periods
Good night, 2 days of struggle I managed to get this result, however, I’m not able to take the daily average per month and weekly average per year. 1 Query SELECT a.Ano, a.Mês, a.Reviews FROM (…
-
0
votes0
answers18
viewsHow do I connect Arduino with esp-01 to myphpadmin?
I have a mega Arduino attached to a esp-01 as follows Arduino-------------esp-01 3v3 gnd------------------gnd Tx-----------------Tx Rx-----------------Rx reset-gnd | en--gnd…
-
0
votes1
answer28
viewsMysql - Select the most inserted records in a given period
I am needing to select all most recurring records (top 5) within a time interval but am not getting. Basically when I do this: SELECT assunto, count(*) AS total FROM tabMsgs WHERE dtCriacao >…
-
0
votes2
answers43
viewsHow to calculate the cumulative sum/subtraction of previous records in SQL?
I’m trying, unsuccessfully, to create a column SALDO in order to keep track of the Cash Flow balance. I imagined doing this in SQL itself, generating a column that would calculate the balance. For…
-
0
votes0
answers60
viewsReturn multiple lines, in a single comma separated by ORACLE
I need to bring these results, in a single line, where it is only separated by a comma, how do I do that? Query: SELECT ' '|| (SELECT DECODE(MAX(g.ds_opcao),NULL,'',MAX(g.ds_opcao)||' - ') FROM…
-
0
votes0
answers7
viewsRight parenthesis error on the base line
I am running a database database. the use of liquibase is mandatory. What I always do, is run the local queries and after everything ok, mount the base with the query inside the changeSet down…
-
0
votes0
answers31
viewsAlign populated values by columns using case when in mysql
As I could align the values in this SQL query per column, are 2 possible questions for each question in a list of several users who answered the first and second question: question one? answer a…
-
0
votes0
answers41
views -
0
votes0
answers12
viewsSQL Server error in UPDATE column with Always Encrypted
I’m implementing in a bank SQL Server the Always Encrypted which serves to encrypt columns of a table. The process of creating the certificate, link it in a table/cokuna and use it in the SQL Server…
-
0
votes1
answer44
viewsGroup by month (in each column) SQL
I am using the code below to make the column of the month of January, but I could not find a way to return the month of February to the side. SELECT CASE WHEN CODGRUPOPROD LIKE '20%' THEN 'TALHA…
-
0
votes2
answers81
viewsLIMIT 1 with LEFT JOIN
Good to start I will post the SQL I rode here: SELECT a.*, b.name AS currentClubName, c.name AS transferorClubName, d.name AS contactName, d.phone AS contactPhone, d.phoneApp AS contactPhoneApp,…
-
0
votes0
answers39
viewsHow to use one column to get value from the other in PL/SQL
I have the following tables in PL/SQL: employees ( employee_ed, first_name, last_name, phone_number, hire_data, job_id, salary, manager_id, department_id ) departments ( department_id,…
-
0
votes2
answers37
viewsTurn Row Columns into sql
Good morning Personal, Have the following query: DECLARE @DTINICIAL AS DATE DECLARE @DTFINAL AS DATE SET @DTINICIAL = '202101[![inserir a descrição da imagem aqui][1]][1]01' SET @DTFINAL =…
sqlasked 3 years, 4 months ago Wanderson Fernandes 1 -
0
votes1
answer42
viewsSelect Conditional with another Select
I’m using SQL Oracle. I need to return a Select that depending on the value of the column GRUPO_ECONOMICO_ID (needs to be equal to 87) it must run a Select, otherwise it must run another select... I…
-
0
votes1
answer39
viewsError accessing state change that has a country
I have a state register, which has a country. It registers normal, only that error occurs when accessing the state change. I don’t know if it’s right, but from what I understand, something from the…
-
0
votes1
answer88
viewsHow many days a week (Monday, Tuesday...) do you have in a 1-month period?
I need help to return in an SQL the amount you have of each day of the week in a period of 1 month, for example in the month 06/2021 has 4 Mondays,5 Tuesdays,5 Wednesdays...etc. I need to know the…
-
0
votes1
answer42
viewsSelect with 3 conditions and one dependent on a fourth condition
I am populating a chart and for that I need to select the data of each user in the database, table financeiro. Still don’t want to show field records label_chart that are empty, nor fields…
sqlasked 3 years, 4 months ago Eugenio de Castro 3 -
0
votes1
answer43
viewsthe identifier 'DMBS_OUTPUT.CHARARR' must be declared plsql oracle
I am writing the following plsql code: declare tab dmbs_output.chararr; qtlines number default 3; res varchar2(100) default null; begin dbms_output.get_lines(tab, qtlines); dbms_output.put_line(…
-
0
votes1
answer33
viewsDoubt column concatenation
The code below returns a sum per classification. Something like this: Services = type 1 Materials = type 2 the expected result is that there is only one row, and that in this Row I have the value of…
-
0
votes0
answers27
viewsOptimize Mysql query with Sub Select
I was having a problem of slowness in a select as below: select vendas.codigo, vendas.cartao_tipo, vendas.valor, vendas.datavenda, venda.autorizacao, cliente.codigo, cliente.nome, cliente.cpf,…
-
0
votes0
answers19
viewsTO_DATE method in Oracle SQL is generating an unintentional Timestamp, how to remove it?
I have a column called 'periodo_filter' with date of type (data1 A data2), example: (01/1/2000 A 19/1/2020). With the following code I am removing the first date from this column and creating a new…
-
0
votes1
answer51
viewsSet age from date of birth in another table
I’m trying to create a Trigger to set the table age attribute funcionario: ```sql CREATE TABLE IF NOT EXISTS `funcionario`( `cpf_funcionario` INT(11) NOT NULL, `idade` SMALLINT(10) DEFAULT NULL,…
-
0
votes0
answers35
viewsReturn names that have no registered workshop
Good afternoon, I would like a help to return names that do not contain the workshop'2' in the registered case. The way I rode, it brings me different from (''), I need that besides different, bring…
-
0
votes0
answers36
viewstype 'Future<Dynamic>' is not a subtype of type 'Set<Marker>'
Basically this code searches for the delivery locations already inserted in the databank and adds a marker on the map for them, in addition to showing the real-time position of the user. The error…
-
0
votes0
answers28
viewsWrite data from two Datagridview to the Sql Server database
I’m not able to record the data that are in two dataGridView, the data that are in the two Datagridview are in a single Class, I have a code ready but would serve only for a Datagrid, in the same…
-
0
votes0
answers31
viewsHow do I Compare fields from different tables using HAVING
I’m trying to make an SQL query in Firebird where it will only return data if the sum of the fields in the first table is different from the Field "vlrnota" of the second table. However, when trying…
-
0
votes0
answers46
viewsSeparate parent and child field from the same table on a row in the oracle
I have a table that has a father-son relationship: code product Cod father degree 1 banana pie 10 3 2 apple pie 11 3 10 banana 111 2 11 apple 111 2 111 fruit -9999999 1 I need to bring the fields…
-
0
votes1
answer50
viewsI am making an online calendar and can not have 2 schedules scheduled on the same day and at the same time for the same professional Mysql PHP PDO
I’m making a website for a barber shop and I need to solve a little problem, in this schedule there are 3 professionals who work in the barbershop, and have the option of choosing the professional,…
-
0
votes0
answers15
viewsMy variable is not in the group - Error
I am running a query but is giving the error. In Databricks is appearing the following message: "Analysisexception: Expression 'Aux1.nom_canal_escritorio' is neither present in the group by, nor is…
-
0
votes0
answers39
viewsDifferences of grade!
I have a situation where I need to validate the records that are in the books and the records that are in financial. I know there’s 51 bills in accounting and 52 in finance. I need to assemble the…
-
0
votes1
answer32
viewsFunction to create buttons according to the database
I have in my database several information and that for each information there should be a button that directs the user to the screen where a guide will be displayed according to the chosen option.…
-
0
votes0
answers22
viewsDoubt query SQL Nodejs
I have the following question in my project for a college job: I need, in a specific route, to show the user’s data, which consists basically of his personal data and the posts he has performed. The…
-
0
votes1
answer31
viewsHow to check the latest registration for the latest?
have the following query sql - code below - and I would like to increment in it a "filter" of the most recent Insert so that the query is the latest pro Insert. $sql = " select ec.id_contrato,…
-
0
votes0
answers32
viewsThere is a table in which the column is called DATE and when trying to select this column the oracle does not let. Does anyone have an idea what to do?
SELECT A.DATE FROM TESTE A; ORA-01747: invalid specification for user.table.column, table.column or column 01747. 00000 - "invalid user.table.column, table.column, or column Specification" After I…
-
0
votes0
answers31
viewsHow to convert DATETIME to DATE using NOW function?
Can you give me a hint of how I can get around the problem below ? The goal of the Query below is to return the number of times I have received ABANDON, CONGESTION and MACHINE service status during…
-
0
votes1
answer18
viewsDúvidas Group by (ireport)
I am using the same query: Select TAB.DESCRPROD, PRO.DT_INC, PRO.QTD_FALT, PRO.OBS, PRO.CODPROD, RETIRA, PRAZO, PREV_ENTREGA, NRO_OF, NRO_OP, MODELO, SEPARACAO, MONTAGEM, GAB, PROD_CLIENTE, STATUS,…
sqlasked 3 years, 3 months ago Marco Moleti 1 -
0
votes0
answers23
viewsBring result from a select that depends on another
Good morning, I have a question regarding SQL. Currently I have 2 querys where one needs the result of the other to return everything I need, and I wanted to know if I can transform the 2 querys in…
-
0
votes0
answers33
viewsDifference of results between sum with pivot and sum of counters
Hello, I would like a support to understand why the following two querys produce different results. The strategy I searched with them is the same, to count and group Sip results with different…
-
0
votes2
answers37
viewsHow can I apply increase and percentage reduction over unit value
The script below calculates the consumption value for materials and medicines , grouping by patient. select coalesce( sum ( ( (L.QTDE) - coalesce( sum( ( select sum(QTDE) from GECADDEV CD inner join…
-
0
votes2
answers40
viewsConsultation with Count
I have the following table : Product status SELECT id_produto_status_history, status, description, create_date, id_produto FROM produto_status_history; where I store product history status There is…
-
0
votes1
answer26
viewsChanging primitive fields and constraints Modify with MARIA DB
The commands Modify and change column are used to change both the primitive fields and the constraints and field name. alter table pessoa modify column profissao varchar (30) not null; alter table…
-
0
votes0
answers12
viewsHelp with Group By on an Inner Join Sql Server
Good morning Gentlemen. I have the following Sql Query below that links data from two tables, the table Tab_dados_producao and Tab_data_choice Code: SELECT…
-
0
votes0
answers23
viewsHow to sum the columns without multiplying the sums?
When I run this query it sums the columns several times in the same number of outputs in the table itemsaida. select p.idproduto codigo, p.descricaoproduto nome, sum(e.qtde) entrada, sum(s.qtde)…
-
0
votes0
answers25
viewsQuestion about filter with dates
I’m a beginner in SQL, and I’m working on a project on Oracle. I got stuck in a situation that theoretically would be simple to solve, but I don’t succeed. They can help me? Below follows the code…
-
0
votes0
answers17
viewsSQL - Using COUNT doubt
Hello, I have the following question: Select the id and the total number of rentals (rental) of the ((a) client (Customer) that made the largest number of rentals. (tip: use COUNT, MAX, nested…
-
0
votes1
answer37
viewsHow to use SUM in a multi-return code?
I did it in a code where it makes a sum of data entered in the months, but I don’t know how to make the AS become a array. The Code I made: DECLARE @I INT = 1; WHILE @I < 12 BEGIN SELECT…
-
0
votes0
answers24
viewsTable relationship command not working
Good afternoon, I have a function with a query to search a list of photos of a certain product in the Product class: class Produto { private $mysql; public function __construct(mysqli $mysql){…
-
0
votes1
answer30
viewsHow can I solve this equation in SQL? X = (A - (B+C+D+E))
I have a table with the following columns: COD_PRODUTO|PRODUTO|UNIDADE|FAMILIA|ORIGEM|ESTOQUE_ATUAL|COMPRAS_ENTRADAS|CONSUMO_PRODUCAO|ENTRADA_PRODUCAO|ESTOQUE_MIN|CMC|DIFERENÇA|PREÇO_REPOS I need to…
-
0
votes1
answer20
viewsGroup By of 1 Oracle SQL Column with latest date
I have a table (TVIC_ODS_MVEL_PRQE), in ORACLE SQL, with millions of records and need to extract from it only 2 columns: phone number (NU_TLFN) and date (DT_PRMR_ATVC_LNHA). The problem is that I…
-
0
votes1
answer33
viewsDuplicate column of a table for itself by changing only the ID
Good morning everyone, I have a doubt and I found nothing similar that can help me, I need to create a copy and put function or duplicate everything this information and generates a new ID keeping…