Posts by anonimo • 4,084 points
322 posts
-
0
votes1
answer22
viewsA: How to subtract extreme indices from the same vector?
Loop up to half the amount of elements. Take the ends (in ascending and descending order) and add the square dd difference. At the end display the calculated sum. #include <iostream> #include…
-
3
votes1
answer47
viewsA: SQL query does not return expected items
Protocols without any analysis: SELECT * FROM protocolo WHERE NOT EXISTS (SELECT 1 FROM analise WHERE protocolo.prefixo = analise.prefixo AND protocolo.numero = analise.numero AND protocolo.ano =…
-
0
votes3
answers1163
viewsA: Error using Else: "'Else' without a Previous 'if'"
You have mistakenly placed a ; right after the if condition and also right after Else. Declared its variables as int but uses the %f flag in the read, which is intended to float. Has a unnecessary…
-
0
votes1
answer61
viewsA: Algorithm that sorts decimal numbers
Substitute: num: vetor[1..3] de inteiro for: num: vetor[1..3] de real and place the aux variable also as real: aux: real…
-
0
votes3
answers113
viewsA: Select two tables
Your question is a little confused but maybe it is: SELECT c.id, c.site, c.cliques_usados, c.cliques, c.localizacao, c.tipo, c.id_user FROM campanha c WHERE NOT EXISTS (SELECT * FROM…
-
1
votes2
answers119
viewsA: How not to update empty fields
COALESCE(valor, ...) Returns the first non-null value of the list of values. If there is no value other than NULL then returns NULL. Could be, for example: COALESCE(valor, 'Não informado')…
-
1
votes3
answers55
viewsA: Switch between results
Check if the date of birth is null and consider the appropriate table. SELECT CASE WHEN i.data_nascimento IS NULL THEN e.id ELSE i.id END AS id, CASE WHEN i.data_nascimento IS NULL THEN e.nome ELSE…
-
1
votes3
answers1056
viewsA: How to convert an integer vector to an integer-only variable?
Take the size of the array and divide it by the size of an element to determine the amount of array elements. #include <stdio.h> int main() { int teste[] = {2, 3, 5, 6}; int i, num=0, tam; tam…
-
0
votes1
answer46
viewsA: Compare difference between values of the same column, having to disregard the first and the last of the day
Try to eliminate these two using sub-selects: select f.nm_funcionario_nome Nome, r.tm_check from tbl_funcionario f, tbl_registro r where r.nm_registro = f.nr_cracha and (r.tm_check > (select…
-
0
votes2
answers1365
viewsA: "ORA-01417: a table may be Outer joined to at Most one other table"
I believe you tried to make a junction referencing more than two tables. Place the joining condition and the other condition in the WHERE clause: SELECT A.SEQPESSOA, A.NUMERONF, A.NROEMPRESA,…
-
1
votes1
answer95
viewsA: I need help solving this exercise (e.g.: 8 project Uler)!
The program below finds the biggest product, but I believe the question calls for the thirtieth largest and not the greatest of all. For this I believe that the easiest way would be to store the 996…
-
0
votes2
answers73
viewsA: Variable is not receiving value - C#
I believe that because it is a division between integers the result of (counter / Maximum) will always be zero for any counter value less than Maximum. Try to convert this operation to real or…
-
0
votes1
answer39
viewsA: SQL subquery - Replicated values
Test replace this junction only by checking if there is record in HISTLISE that satisfies the condition: (SELECT COUNT(P.DTENG) FROM PARHILISE AS P WHERE EXISTS (SELECT * FROM HISTLISE AS H WHERE…
-
0
votes1
answer284
viewsA: Oracle SQL - select only clients with more than one order, listing items from two ID tables, EMAIL and ID_ORDER
Merge the tables and take only the records that have an order amount greater than 1. SELECT c.ID, c.EMAIL, o.ID_ORDERS, COUNT(o.ID_ORDER) FROM CUSTOMERS c INNER JOIN ORDERS o ON (c.ID = o.ID) GROUP…
-
2
votes4
answers7488
viewsA: How to change the database name in Mysql Workbench 8.0 using ALTER DATABASE?
There is no single command in Mysql to rename a database. You can use the command: RENAME TABLE banco_atual.nome_tabela TO novo_banco.nome_tabela; for each of the current bank tables which, for…
-
0
votes1
answer31
viewsA: Psql -c is lowering my table name
Put the escape character in the name of your table: psql -d copia-local -U postgres -c "COPY \"Questions\" FROM '/home/pedro/Documents/PostGre/data/cooked/Questions_cooked.txt' WITH DELIMITER '|'…
-
1
votes2
answers47
viewsA: I a select where the same is starting to get too slow, Would you have any solution to improve your speed?
It seems to me that you make a huge and unnecessary amount of subselects. At least here: (SELECT empresa.`Empresa_Codigo` FROM empresa WHERE empresa.`Empresa_Id` = fhe.`Empresa_Empresa_Id` LIMIT 1)…
-
1
votes2
answers672
viewsA: Recursive function
The maximum common divisor (mdc) of the integers x and y is the largest integer that is divisible by x and y. It is defined as follows: mdc(x, y) = y, if x >= y and x mod y=0 mdc(x, y) = mdc (y,…
-
0
votes4
answers428
viewsA: Receive various values and print only the 3 largest ones in c
Initialize with an invalid value (I used -1) and at each read check if it is one of the first three, move the smallest and put it in place. #include <stdio.h> int main() { int pon = 0, plu=-1,…
-
0
votes1
answer31
viewsA: Query SQL Help
Try: SELECT n_acid, marca, COUNT(*) FROM marca_acid as ma INNER JOIN veiculo as v ON (ma.veic_seguro = v.n_veic) GROUP BY n_acid, marca; Ideally you would qualify the table of each field, which you…
-
1
votes1
answer44
viewsA: Error in data printing
You read N times the string word and overwrite all readings, so it will only treat the last one. To treat word for word do: #include <stdio.h> #include <ctype.h> #include…
-
0
votes5
answers5734
views -
0
votes2
answers206
viewsA: How to use GROUP_CONCAT in the WHERE clause, with numbers?
You can do it in a simpler, more efficient way using the NOT EXISTS clause: SELECT * FROM bois WHERE NOT EXISTS (SELECT * FROM bois_manejo WHERE bois_manejo.fk_boi = bois.id);…
-
0
votes3
answers477
viewsA: How to account for the number of primes in a matrix?
Correcting your check if the number is prime. int divisores = 0; int qtd = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 5; j++) { divisores = 0; for (int c=2; c<=matriz[i][j]/2…
-
0
votes2
answers43
viewsA: Query to know which books students do not have, in SQL
Unregistered books: SELECT * FROM Livro WHERE NOT EXISTS (SELECT * FROM RegistroLivroAluno WHERE RegistroLivroAluno.ID_Livro = Livro.ID_Livro); Unregistered students: SELECT * FROM Aluno WHERE NOT…
-
1
votes4
answers1889
viewsA: Fill vector in C
Missing a loop to print. Note that after the read loop the variable i will contain the value 5, which is outside the vector boundary. #include <stdio.h> #include <stdlib.h> #include…
-
0
votes1
answer69
viewsA: Select different conditions for the same column
Use a CASE within the SUM function: select TO_CHAR(FROM_TZ(TO_TIMESTAMP(TO_CHAR(hi.data, 'yyyy/MM/dd hh24:Mi:ss'),'yyyy/mm/dd hh24:mi:ss'), 'UTC') AT TIME ZONE 'AMERICA/SAO_PAULO', 'dd/mm/yyyy') as…
-
0
votes1
answer120
viewsA: vector logic portugol
Except for the first compare with the index element - 1. Algoritmo "semnome" Var vetNum: vetor [1..25] de inteiro i: inteiro Inicio para i de 1 ate 25 faca leia(vetNum[i]) se (i > 1) entao…
-
1
votes2
answers87
viewsA: Postgres SELECT FROM
Try: $sql = $pdo->prepare('SELECT * FROM \"Teste\".\"$Pessoas\"'); But this is not related to Postgresql.
postgresqlanswered anonimo 4,084 -
2
votes1
answer714
viewsA: Error in Visualg, I put the then and still gives error, already tried to put the condition between parentheses too
You make an infinite loop: enquanto (1 = 1) FACA but within your loop there is no test or condition for you to jump out of the loop. This here: se (esc <= 0) ENTAO fimse doesn’t make any sense.…
-
2
votes2
answers85
viewsA: How to make the user re-enter the numbers at the beginning of the program?
Change: while pergunta1!='A' or 'B' or 'C' or 'D' or 'E': for: while pergunta1!='A' and pergunta1!='B' and pergunta1!='C' and pergunta1!='D' and pergunta1!='E': but it would be better: while…
-
0
votes1
answer202
viewsA: Unicodedecorror when reading CSV file
There is no UTF-8 character that is or starts with 0X85. Its enconding does not match the encoding used in creating the file.
-
1
votes2
answers117
viewsA: How to get lower value without aggregation function - SQL
SELECT * FROM estudante WHERE NOT EXIST (SELECT * FROM Estudante est_aux WHERE estudante.idade > est_aux.idade);
-
0
votes3
answers1358
viewsA: Problems adding Foreign key to Mysql
Here, in the table deals: foreign key (anoAuto) references automoveis(ano)) attribute year does not uniquely define a row of auto table. I don’t know what you’re up to. Maybe your foreign key should…
-
2
votes2
answers2244
viewsA: How to calculate the cumulative sum in Oracle
Try: SELECT Trunc(td.data_emissao) AS data_emissao, Count(*) AS quantidade, (SELECT count(*) FROM tabela_dados tda WHERE tda.trunc_emissao <= td.data_emissao AND Trunc(tda.data_emissao,'mm') =…
-
0
votes3
answers172
viewsA: Hide duplicate SQL values
If I understood correctly your question the SQL expression would be: SELECT * FROM tabela1 CROSS JOIN tabela2 WHERE (tabela1.col1 <> tabela2.col2);
-
1
votes2
answers54
viewsA: Help with Query Mysql
You have left many things open in your clarifications because I do not know what unity is in your example table. Try something like: SELECT profissionais_ab.cns cns_medico, profissionais_ab.cbo,…
-
3
votes4
answers65
viewsA: Beginner program error in C
Your problem is here: if(salario>=0.00 || salario<=2000.00){ Any value will meet such condition (all positive numbers will be greater than or equal to zero and all negative numbers will be…
-
0
votes2
answers35
viewsA: algorithm not doing the necessary checks
Since any number is always divisible by 1 and by itself, for the number to be prime it is sufficient to have no other divisor. Algoritmo "semnome" Var cont, cont2 , x, v1, aux: inteiro Inicio…
-
1
votes2
answers825
viewsA: Division error by zero
Print the split output only if such an operation is possible. #include <stdio.h> int main() { int num1, num2, soma, subtracao, multiplicacao, divisao; printf("Digite o primeiro numero:");…
-
1
votes1
answer42
viewsA: SELECT in 3 database tables with specifications
Try: SELECT emp.id, emp.nome_empresa FROM empresas as emp JOIN funcionarios as f ON f.empresas_id = emp.id WHERE NOT EXISTS (SELETC * FROM guias as g WHERE g.empresas_id = emp.id AND g.tipo =…
-
0
votes3
answers1158
viewsA: Even-odd vector fill C
The use of the % (module) operator can facilitate the control of when each vector was full and therefore must be printed, keeping the count of all numbers, even or odd, already found. #include…
-
0
votes1
answer229
viewsA: Problems in C , storing several different values and doing arithmetic media
Complementing your code: #include <stdio.h> int main(){ float salario, inss, bcalculo, aliquota, deducao, ir, soma_sal=0, soma_ir=0; int dependentes, soma_dep=0, qtd=0, i, faixa_ir[5]={0, 0,…
-
1
votes1
answer189
viewsA: Query in SQL/Firebird grouping a sum by nature
Use the CASE / WHEN construction in the aggregation function: SELECT CC.CODIGO_PRODUTO AS PRODUTO, GS.GRUPO AS GRUPO, GS.CODIGO_GRUPO AS NOME_GRUPO, SUM( CASE CC.TIPO_NATUREZA WHEN "C" THEN CC.VALOR…
-
1
votes2
answers509
viewsA: How to map multivariate attributes?
For your data model to be in first normal form (1FN) it is necessary that the attributes are atomic, that is, they cannot be multivariate. Note that there are Dbms that allow the use of multivariate…
-
0
votes3
answers2698
views -
1
votes1
answer24
viewsA: Do you know of any unique Postgresql features?
Hard to say that a feature is unique to Postgresql because this would imply knowing in depth all the existing DBMS (and that are many) in its various versions. I believe that in addition to the user…
-
1
votes2
answers1247
viewsA: SQL Error [42601]: ERROR: syntax error at or near "Foreign"
Simplify: create table tipo_agendamento_escritorio( id int8 not null, primary key (id), tipo_agendamento_id int8 not null REFERENCES tipo_agendamento (id), prazocomum int8 not null, prazotrabalhista…
-
3
votes3
answers336
viewsA: Catch Fatherless Children in a MYSQL hierarchical structure
First of all it would be enough to put a foreign key constraint on your table that such an error would not occur. Try SELECT id_parent, id, name FROM sua_tabela a WHERE NOT EXISTS(SELECT 1 FROM…
-
0
votes3
answers865
viewsA: Select with due dates
Whereas you are referring to the SQL language. SELECT valor, vencimento FROM sua_tabela WHERE status = 'Pendente' AND vencimento < date_trunc('month', CURRENT_DATE + interval '2 month');…