Posts by anonimo • 4,084 points
322 posts
-
-1
votes3
answers121
viewsA: Compare birth date registered in the database to a custom date - mysql
Make sure this is what you want: SELECT * FROM clientes WHERE data_de_nascimento <= DATE_SUB(CURDATE(), INTERVAL 60 YEAR);
-
1
votes1
answer24
viewsA: SQL - How to take a data from a table and insert another preset?
If I understand your doubt: INSERT INTO `usuarios_placas`(`username`, `code_placa`) SELECT username, 'sua string do emblema' FROM usuarios
-
0
votes1
answer95
viewsA: I need to update the value of one SQL table with the sum of the values of another
Use a subselect with the aggregation function SUM along with GROUP BY numero. UPDATE nfpse SET total_serviços = (SELECT SUM(valor_unitario * quantidade) FROM nfpse_detalhe WHERE nfpse.numero =…
-
1
votes1
answer23
viewsA: SQL-Obtain code of the employees who participated in all projects
What Motta suggested was: SELECT E.Nome FROM Empregado E WHERE NOT EXISTS (SELECT P ProjNum FROM Project P WHERE NOT EXISTS (SELECT A.ProjNum FROM Atribuicao A WHERE A.ProjNum = P.ProjNum AND…
-
1
votes1
answer164
viewsA: Python Recursiveness - Rest of the division of two numbers
A solution: def resto(n, m): if (n < m): return (n) else: return resto(n-m, m)
-
2
votes2
answers202
viewsA: Force while loop output on C switch
I think what you want is: int opcao; do { menu(); printf("\nOpção selecionada: "); scanf_s("%d", &opcao); switch (opcao) { case 1: adicionar(); break; case 2: modificar(); break; case 3:…
-
1
votes2
answers699
viewsA: Multiples of 2 numbers in C
From what I understand of the problem you want to calculate the n and not limit each of the multiples to n. An idea is: #include <stdio.h> int main() { int n, i, j, k=0, cont=0, mult_i=0,…
-
0
votes2
answers326
viewsA: Number represented as sum of square of consecutive primes in C
Try: #include <stdio.h> #include <math.h> #define TRUE 1 #define FALSE 0 int main() { int p1=2, p2=3, p3=5, p4=7, next, i, n, prime; printf("Entrada: "); scanf("%d", &n); while…
-
1
votes2
answers860
viewsA: Check if number is equal to the sum of squares of 4 consecutive prime numbers
Try: def ehprimo(num,primos): for divi in primos: if num%divi == 0: return False return True num,cont,primos = 2,1,[] while cont <= 100000: if ehprimo(num,primos) == True: cont += 1 print(num)…
-
0
votes2
answers398
viewsA: Multiple of a number in C
What you want is the MMC - Common Minimum Multiple of the three numbers. By definition: - mmc(x,y) = (x * y) / mdc(x,y) - mmc(x, mmc(y, z)) = mmc(mmc(x, y), z) #include <stdio.h> int mdc(int…
-
0
votes1
answer66
viewsA: Force user to enter integer numbers in an array
Although you say it’s correct you’ve noticed that here: while (continuar = 1){ you are assigning 1 to the variable continuar and not checking if its value is 1? int consumidor[50]; int i = 0,…
-
0
votes3
answers95
viewsA: If counter in a text file
Option traversing the read string: #include <stdio.h> #include <stdlib.h> #include <string.h> void main() { FILE *arq; char str[255], *p; int count = 0; arq =…
-
3
votes1
answer31
viewsA: Filtering results with Postgres selects
You can use a subquery: SELECT * FROM resultados a WHERE a.data = '20200220' AND EXISTS (SELECT 1 FROM resultados b WHERE b.idEmp = a.idEmp AND b.data = '20200221'); A question: if it is a date for…
postgresqlanswered anonimo 4,084 -
1
votes1
answer40
viewsA: What is the difference between operators <@> and <->
The operator <-> (distance between 2 objects), defined in Postgresql itself, is used with objects of a two-dimensional space. The operator <@> (point <@> point), defined in the…
-
0
votes1
answer528
viewsA: Mysql - Cannot add or update a Child Row: a Foreign key Constraint fails (`areas_knowledge`. `sub_areas`,
According to your file: "areas": [ { "codigo": "10100008", "nome": "Matemática", "sub-areas": [ { "codigo": "10101004", "nome": "Álgebra", but in your INSERT you specified: INSERT INTO…
-
5
votes2
answers98
viewsA: Warning: format '%f' expectts a matching 'double' argument (en)(en)
Several errors. Here: printf("\nA media do aluno é: %f"), proceNotas(n1, n2, n3, letra); should be: printf("\nA media do aluno é: %f", proceNotas(n1, n2, n3, letra)); Your calculations are wrong.…
-
0
votes1
answer48
viewsA: Postgres SQL query with table relations
Assuming your last table is the table tweets, from what I understood of your doubt: SELECT * FROM folowings INNER JOIN tweets ON folowings.contact_id = tweets.user_id; If you have misunderstood your…
postgresqlanswered anonimo 4,084 -
2
votes2
answers48
viewsA: SQL showing records if they only meet different conditions than usual
Using the IN clause: SELECT * FROM AUTOR WHERE ID IN (SELECT ID_AUTOR FROM LIVROS GROUP BY ID_AUTOR HAVING MIN(ANO) >= 1919);
-
1
votes1
answer46
viewsA: POSTGRES) Questions about the blob dump
I think you should refer to the following option in the documentation: -B --no-blobs Exclude large objects in the dump. When both -b and -B are given, the behavior is to output large objects, when…
postgresqlanswered anonimo 4,084 -
1
votes1
answer50
viewsA: Query with Left Join considering the most recent records from the auxiliary table
If the field lem_datais effectively of the type date then try: SELECT curriculo.cur_nome, max(lembrete_envio.len_data) FROM curriculo LEFT OUTER JOIN lembrete_envio ON (curriculo.cur_codigo =…
-
0
votes1
answer57
viewsA: variable pass by reference between function in c
The way you defined your function the parameter flag is being passed by value, that is, a copy of the existing value in main is copied to the stack and any modification made to the function is done…
-
-1
votes6
answers623
viewsA: What is the reason for the application of the concept LIFO (Last In, First Out)?
The use of the data structure pile is one of the ways to calculate the result of an algebraic expression using Polish inverse notation to represent the expression. In practice we use infix notation,…
computer-scienceanswered anonimo 4,084 -
0
votes1
answer73
viewsA: Add two columns and subtract with condition
An alternative is: SELECT SUM(CASE WHEN lancamentotipo = "R" THEN valor WHEN lancamentotipo = "D" THEN -valor ELSE 0 END) AS resultado FROM lancamentos; If "R" and "D" are the only possible values…
-
2
votes2
answers193
viewsA: I was given this exercise: "ALL CUSTOMERS WHO BOUGHT MORE THAN R$ 200,00 LAST MONTH"
The clause HAVING may be useful for solving your problem. Assuming there is a field data in your orders table and that "last month" is the month before the current month try: SELECT clientes.nome,…
-
1
votes1
answer21
views -
1
votes1
answer221
viewsA: Postgresql - Importing . CSV into an existing table
According to what you informed in your question: If the.csv file is on the postgresql server machine use the SQL command: COPY cnpj.cnae(cnpj, cnae, nat_jur) FROM 'G:…
-
2
votes3
answers182
viewsA: Select returns nothing when I have NULL in foreign key
The way you rode your SELECT you’re making a INNER JOIN. Replace with a LEFT OUTER JOIN: SELECT a.codigo, q.nome as nomesubprojeto, a.subprojeto FROM comprovante a LEFT OUTER JOIN subprojeto q ON…
-
0
votes2
answers3178
viewsA: Format float in Python
Try: print('O peso médio dessas pessoas é: {:.{prec}f}'.format(media, prec=2)) or, simplifying: print('O peso médio dessas pessoas é: {:.2f}'.format(media))…
python-3.xanswered anonimo 4,084 -
1
votes2
answers246
viewsA: Query Mysql to count contracts with INNER JOIN
As clarified in the comments: SELECT DISTINCT `contrato`.`num_contrato` FROM `tb_contrato` `contrato` JOIN `tb_fatura` `fatura` ON `fatura`.`contrato_id` = `contrato`.`id` WHERE `bill`.`valor` >=…
-
2
votes1
answer67
viewsA: Sublime Text does not work properly
The problem is not with the sublime text but with the system("pause");in the linux environment. Replace with: std::cout << "Press enter to continue ..."; std::cin.get();…
-
0
votes1
answer97
viewsA: How to remove the string from a given range
See if this is it (I changed the substring limits to have a smaller input): #include <iostream> #include <string> using namespace std; string cod[100]; char numnota; int main() { string…
-
5
votes1
answer140
views -
1
votes2
answers169
viewsA: How to make a group by Select is done to more than one table
As you are doing a random CROSS JOIN see what the result of the command below is and, if so, what needs to improve: SELECT tblOrgao.eleicao_id as IdEleicao, tblCargo.orgao_id as IdOrgao,…
-
0
votes1
answer40
viewsA: circular list jump
See if this is what you want: #include <stdio.h> #define VIVO 0 #define MORTO 1 int main (){ int m, p, n, i, sobreviventes, pos, j, k, l; scanf("%d %d %d",&m , &p, &n); int vet[m];…
-
0
votes2
answers717
viewsA: How to separate vowel consonants into a matrix in C
Why do you define vowel and consonant arrays with 8 and 10 positions respectively? If they are all vowels, shouldn’t they be vowel[18]? Idem for if they are not, then according to [18]? If you want…
-
2
votes2
answers55
viewsA: How to make a codition inside a NOT IN on Sqlserver
By your explanation I deduce you want to remove the plates 5,6,7 this is: t. matricula NOT IN (5, 6, 7) but if the situation is 'Closed' then consider, regardless of registration, then use: t.…
-
0
votes1
answer167
viewsA: Mask to turn integer into string - Postgresql
The problem is in the size of your field num_proc. SELECT char_length(to_char(123456789123,'99"-"999"."999"/"99"-"99')); char_length ------------- 17 (1 registro) Increase the size of your field to…
postgresqlanswered anonimo 4,084 -
0
votes1
answer25
viewsA: How to convert a Mysql view to Postgresql?
Use CASE: CREATE VIEW anuncio_points AS SELECT a.*, (CASE WHEN p.points is null THEN 0 ELSE sum(p.points) END) + u.points as points FROM anuncios as a LEFT JOIN users as u ON u.id = a.user_id LEFT…
-
1
votes3
answers101
viewsA: Return value corresponding to date
See if this is it: SELECT (CASE WHEN EXISTS (SELECT 1 FROM tabela aux1 WHERE aux1.data_saida = data_desejada::date) THEN (SELECT custo_saida FROM tabela WHERE data_saida = data_desejada::date) ELSE…
-
0
votes2
answers492
viewsA: How to check if there are only numbers in the CPF and CEP in SQL
If you are using Postgresql, which seems to me to be the case, you can use regular expressions: teste=# SELECT regexp_replace('03365282050', '[[:digit:]]+', '', 'g') = ''; ?column? ---------- t (1…
-
0
votes2
answers53
viewsA: Aggregation error only in postgresql 9.4
Make sure this is it: SELECT materiais.id material_id, insumos.nome material_nome, apresentacoes.id apresentacao_id, apresentacoes.apresentacao apresentacao_apresentacao, estoques_total.setor_id,…
-
1
votes2
answers522
viewsA: Current value of an "auto increment" field in Postgresql
In the PostgreSQL an "auto increment is a field with data type serial or bigserial. A guy serial is nothing more than a whole with a sequence associated. To manipulate sequences you have the…
postgresqlanswered anonimo 4,084 -
1
votes2
answers121
viewsA: Select higher value between Mysql Joins
Your query makes the Join of 5 tables. Try: SELECT *, GREATEST(cursos_aulas_videos.data_cadastro, cursos_aulas_imagens.data_cadastro, cursos_aulas_exercicios.data_cadastro,…
-
0
votes2
answers103
viewsA: sql Where with max(timestamp)
If there may be multiple departures on that date use: SELECT partida_id FROM partida WHERE data = (SELECT max(data) FROM partida);
-
1
votes1
answer44
viewsA: Doubt in Select
Try: SELECT modalidades.* FROM modalidades LEFT JOIN inscricoes ON (modalidades.id = inscricoes.id_modalidade) WHERE inscricoes.id_modalidade IS NULL; If you need the name of the championship:…
-
0
votes4
answers114
viewsA: Doubt QUERY SQL construction
See if it answers: SELECT TB1.CODIGO, TB1.DATA, TB1.VALOR FROM TB1 LEFT OUTER JOIN TB2 ON (TB1.CODIGO = TB2.CODIGO AND TB1.DATA = TB2.DATA) WHERE TB2.CODIGO IS NULL OR TB2.DATA IS NULL OR TB2.VALOR…
-
0
votes1
answer54
viewsA: Visualg - doubts about how to stop
Initialize your accumulators. The "while" test is wrong. Print totals only at the end. algoritmo "Exercício" Var Cont, EleitorObrigatorio, EleitorFacultativo, NaoEleitor, idade, i : Inteiro Inicio…
-
-1
votes5
answers79
views -
0
votes1
answer32
viewsA: I’m not getting the vector from the subprogram into the program,
Several errors. Try: #include <stdio.h> void NrVector(int *, int); int main() { int j, y, z, h; printf("Introduza o nr de numeros que pretende introduzir:"); scanf("%d", &j); int…
-
2
votes1
answer66
viewsA: Intervals between two date columns
See if it answers: SELECT (CASE WHEN data_inicial < '2019-09-01' THEN '2019-09-01' ELSE data_inicial END) AS inicio, (CASE WHEN data_final > '2019-09-30' THEN '2019-09-30' ELSE data_final END)…