Questions tagged as 'sql'

2
answers

Select certain amount of data for each type status

Billy Jow here! In my historical table I have a status field that can take four possible values: 'EVALUATE', 'FAIL', 'REVOK', 'SUCCESS' I want to select 20 records of each status where the date is most recent. Since I want only th...
asked by 11.11.2017 / 14:33
1
answer

Is it wrong to leave an FK inside the table that originates the PK?

Is it wrong to do this on a bank table? I'll cite an example: We have the Client: Google And in it we have the unit: Google Brazil Then we have the following table example: Client Table Id | Nome | Matriz 1 | Google...
asked by 17.10.2014 / 15:41
1
answer

Sub select with COUNT and SUM

I have the following query : SELECT s1.suprimento, e1.numeroserie, s1.capacidade, e1.numeronotafiscal, e1.valorunitario, e1.datanotafiscal FROM public.estoque e1, public.suprimento s1, public.fornec...
asked by 19.03.2018 / 13:53
2
answers

doubts with query in sql

I have a table with 5 fields: id name charge salary data ... and I wanted to make a query that would return the names of the people with the highest salary, of each position, for example I have 3 positions: analyst, dev and engine...
asked by 21.07.2017 / 13:19
1
answer

Qt SQL - ERROR (42601): syntax error at or near

I'm currently developing a program to help manage a barracks in my city, I'm using Qt to create the graphical interface and other necessary libraries like database manipulation, for the server I'm using postgres , when trying to cre...
asked by 31.08.2018 / 13:44
2
answers

Doubt in function in PostgreSQL

I'm doing a function in PostgreSQL and I want to use it to check whether a table already exists or not in a database, and if it does not exist, I want to create the table. The problem is in the function statement, which receives varchar...
asked by 19.09.2018 / 02:03
1
answer

ERROR # 1111 - Invalid use of group function (SUM | COUNT)

This query gives me the total attendance of two parliamentary groups (eg PS, PSD) between two dates: SELECT DISTINCT a.partido, (SELECT COUNT(presencas.assiduidade) FROM presencas, reunioes WHERE presencas.assiduidade = 'Presença (P)' A...
asked by 30.08.2017 / 04:15
2
answers

SQL Query - CASE with LEFT JOIN

I need to create a query that returns all active students and their grades for each subject. If the student does not have a grade for a given subject, the student must return the subject and note the value "No grade". I think I'll need to cre...
asked by 20.05.2017 / 23:38
2
answers

Error in SQL result

Well, this is what I'm doing, I'm having to do a select in a database, where I should look for values that exist between two dates, and that have a specific user. I made the select like this: SELECT * FROM 'tabela' WHERE 'data' BETWEEN 'dataIn...
asked by 31.05.2017 / 21:01
1
answer

View with parameters without external?

I need to get parameters for a view , but since it has COUNT(DISTINCT DTA_HOR) I can not get the where external. Would it have any other way? SELECT EX1 ,EX2, EX3, EX4, (SELECT COUNT(DISTINCT DTA_HOR) FROM TB_1 WH...
asked by 25.05.2017 / 23:21