Posts by anonimo • 4,084 points
322 posts
-
0
votes2
answers36
viewsA: compare case result
In Postgresql you could do: SELECT pr.ean, upper(pr.nome) AS nome, pr.unidademedida, se.quantidade, pr.customedioinicial, (CASE WHEN fpp.customedio>=0 THEN TO_CHAR(fpp.customedio, '99999') WHEN…
-
0
votes1
answer262
viewsA: How to generate a variable with random value in C
The program below generates 5 pseudo-random numbers between 1 and 10: #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int num, i; srand (time(NULL)); for…
-
1
votes2
answers118
viewsA: Basic SQL (Join and Where)
To get the cheapest ivro from each author do: SELECT autores.nome, livros.isbn, MIN(livros.valor) FROM autores INNER JOIN livros_autores ON (autores.cod = livros_autores.id_autor) INNER JOIN livros…
-
1
votes2
answers57
viewsA: Count product output on day in mysql
As Dbalone said: SELECT produto_id, data_uso, SUM(qtd_saida) as total FROM tbl_limpeza_saida_diaria WHERE produto_id=7 AND data_uso=DATE(NOW()) GROUP BY produto_id, data_uso;…
-
1
votes3
answers92
viewsA: Beginner Language Error C Code Blocks
You do a lot of unnecessary operations. Just: #include <stdio.h> int main() { int dinheiro = 200; int r$100, r$50, r$20, r$10, r$5, r$2, r$1; int inter; r$100 = dinheiro / 100; dinheiro %=…
-
2
votes1
answer123
viewsA: POSTGRES: INNER JOIN 1:N with multiple tables. Need to count and display records that were accessed as a list
Try using UNION for the junctions of each media type: SELECT tipoMidia, titulo, acessos FROM ( (SELECT tipo_midia.tipo, videos.titulo, COUNT(acesso_registro.data_acesso) AS acessos FROM…
-
2
votes4
answers134
viewsA: Mysql query involving Profession and Note information registered in the same column
If I understand correctly: SELECT count(inf_codigo_contrato) FROM sua_tabela WHERE (inf_codigo_variavel=117 AND inf_valor='ANALISTA DE SISTEMAS') OR (inf_codigo_variavel=124 AND inf_valor='OTIMO');…
-
0
votes1
answer74
viewsA: Query to not repeat an already registered value
From what I understand you want those vehicle numbers that exist in vehicles but are not registered in dispatch_occurrences. Try: Select distinct viaturas.vtr_numero From viaturas Where NOT…
-
1
votes1
answer94
viewsA: How to add and store what were the added id?
Try: SELECT SUM(valor) AS soma, GROUP_CONCAT(id) AS ids FROM valor V WHERE V.status = 1 Corrected.
-
0
votes1
answer72
views -
2
votes2
answers25
viewsA: Mysql inserts different value in reference column passed in query
The type of data TINYINT occupies a single byte and thus can represent integer values from -128 to 127. It is impossible to store the entire 373 in one TINYINT.
-
1
votes2
answers46
viewsA: SE - Excel function
If your Office version does not have the SES function try: =SE(E(A1="N"; B1="N"); ""; SE(A1="N"; Verdadeiro; SE(B1="N"; Falso; "Ambos diferentes de N"))) Considering the possibility of the last…
-
0
votes1
answer82
viewsA: How to add in a program that runs at the command prompt in C
In my environment (Ubuntu) ran normally: #include <stdio.h> int main() { printf("Naipes: ♠ ♣ ♥ ♦ ♡ ♢ ♤ ♧ \n"); return 0; } :~/Testes/C$ gcc -o naipes naipes.c :~/Testes/C$ ./naipes Naipes: ♠ ♣…
-
-1
votes1
answer61
viewsA: Command in SQL already with correct calculation
Assuming that in your tables you do not have the note value for recalculation of the ICMS, and therefore you need to recalculate from the ICMS value you have, and that the icms column contains a…
-
0
votes3
answers1052
viewsA: How to select different records between two tables
Starting from your original SELECT, because I did not understand the considerations made later, try: SELECT c1.cod_coletor, c2.cod_coletor FROM item_inventarios c1 FULL OUTER JOIN funcionarios c2 ON…
-
1
votes1
answer510
views -
0
votes2
answers138
viewsA: Problem in realizing the sum of the lines of a two-dimensional matrix C++
To add the columns use the same structure you used for reading: for (int i = 0; i < 3; i++) { vetor[i] = 0; for (int j = 0; j < 3; j++) { vetor[i] += bid[j][i]; } cout << "A soma da…
-
-2
votes3
answers681
viewsA: SQL-Select To calculate seller commission
Try to calculate with a subquery the number of calls for each employee. SELECT funcionario.codfunc, funcionario.nome, (funcionario.salario * 0.1 * (SELECT count(*) FROM atendimento WHERE…
-
-1
votes1
answer52
viewsA: Variables with absurd values in the execution of the program in C
Here: printf("\n O número %d elevado ao quadrado é: %.2f", &numero, pow(numero, 2)); you are printing the address of the variable number and not the content of the variable number. Spin:…
-
-1
votes2
answers117
viewsA: Sort mysql query by numbers present in varchar column
If all lines are in the same pattern as your example, and assuming that currency x is not part of the field content, try: SELECT * FROM sua_tabela ORDER BY (CASE catalogo WHEN 'CJ 0025' THEN 1 WHEN…
-
2
votes1
answer50
viewsA: I have a question about this code snippet - Scanf
%[^\n]: reads a string until you find a ' n' (end of line). %*1[\n]: this * right after the % indicates that what is read will not be assigned to any variable (in this case to discard ENTER).…
-
0
votes2
answers566
viewsA: Select with re occurrences of a period record
I believe what you’re looking for is: SELECT a.codigo, a.data FROM aviso a WHERE a.data IS NOT NULL AND a.data BETWEEN To_Date('01/03/2017 00:00:00', 'DD/MM/YYYY HH24:MI:SS') AND To_Date('31/03/2017…
-
1
votes3
answers2475
viewsA: Return 0 if the value does not exist in the table
Use the function COALESCE. Remember that NULL is not the same thing as zero. SELECT SEQ_RESUMO, COALESCE(COUNT(1), 0) AS sequence FROM INICIO_FIM_COLETA WHERE seq_picking = '244582' GROUP BY…
-
2
votes1
answer316
viewsA: Minimum and maximum cardinality - Relational Model
For this type of relationship (N:N) you have to create an auxiliary table that represents the registration relationship. In this table you will have the foreign keys of each of the entities involved…
-
0
votes3
answers40
viewsA: SQL - Last Registration of each car
You can use the MAX aggregation function: SELECT vehicle_id, MAX(seu_campo_data) FROM sua_tabela GROUP BY vehicle_id; If you need more fields from your table then you can use the above query as a…
-
1
votes3
answers40
viewsA: SQL - Last Registration of each car
You can use the MAX aggregation function: SELECT vehicle_id, MAX(seu_campo_data) FROM sua_tabela GROUP BY vehicle_id;
-
2
votes2
answers343
viewsA: select Count within select
References the most external SELECT instance in subselects: SELECT instancia, (SELECT COUNT(instancia) FROM urt WHERE MONTH(ura_data) = 04 AND a.instancia = instancia) AS abril, (SELECT…
-
-1
votes2
answers120
viewsA: Bingo program does not identify who has won
There are indentation and key closing errors in wrong place. #include <stdlib.h> #include <stdio.h> #include <time.h> int main(){ srand(time(NULL)); int sorteio = 0; int p1 = 0;…
-
0
votes2
answers105
viewsA: creation of tables to register questions in postgresql
You cannot place a field that does not uniquely identify a line as a foreign key in another table. The drawing may lack the relationship between tables table_questoes and Themes. Substitute dominio…
postgresqlanswered anonimo 4,084 -
0
votes1
answer27
viewsA: Compare products for years in different columns of the same table
Try: SELECT coalesce(a.produto, b.produto) AS "Produto", coalesce(a.quantidade, 0) AS "Qtd 2018", coalesce(b.quantidade, 0) AS "Qtd 2019" FROM (SELECT * FROM sua_tabela WHERE ano = 2018) a FULL…
postgresqlanswered anonimo 4,084 -
0
votes2
answers92
viewsA: Passing a vector to a function in C
Correcting incorrect use of indexes and making your show function more general: #include <stdio.h> void show(int[], int); int main() { int vet[5],i; printf("Digite 5 numeros:");…
-
0
votes1
answer71
viewsA: How to create conditional structure in SQL?
In the definition of your table use the CHECK clause. To check age: int idade CHECK (idade > 1 AND idade <=130), For the name: nome char(30) CHECK (nome NOT LIKE '%mentiroso%'),…
-
0
votes1
answer50
viewsA: How to find all prime numbers in a set of bounded values?
Error of indentation, try: lista = [] result = [] cont = 0 for i in range(1, 1001): lista.append(i) for j in lista: for i in range(1, 1001): if j % i == 0: cont += 1 if cont == 2: result.append(j)…
python-3.xanswered anonimo 4,084 -
0
votes3
answers108
viewsA: Problems with a C program
You need to reset the variable counting each number of the range to be tested (at each value of k). #include<stdio.h> #include<locale.h> main(){ setlocale(LC_ALL,""); int…
-
1
votes2
answers44
viewsA: Choose the order in which items are listed in Mysql
Understanding that: ordem2 ordem_especial ordem1 be the content of a given field, you can do something like: SELECT ..., (CASE WHEN campo='ordem2' THEN 1 WHEN campo='ordem_especial' THEN 2 WHEN…
-
0
votes2
answers125
viewsA: Run time exceeded in c
Your number primality check is rather inefficient. It doesn’t actually check whether the number is prime. You can optimize verification by eliminating a good part of the calculations using: bool…
-
0
votes1
answer37
viewsA: How do I create a view in mysql by taking data from 2 or more different tables?
You should have put what you’ve done. As you’re new I’ll answer below but make a tour on how to use this site. CREATE VIEW ProdutosPendentes AS SELECT LstCompras.NmLstCompras,…
-
0
votes3
answers751
viewsA: Compress array by removing zeros [C]
You don’t need to exchange content, you just need to move the following positions to the previous one when it’s zero. #include <stdio.h> int main() { int vet[15]; int i, j, lim=15, k; for…
-
1
votes1
answer169
viewsA: Visualg Exercise Solved :: Wanted tips on how to improve it
One way to specifically address your problem, for an undetermined number of cities, is to: algoritmo "Exercício" var codcidade, codcidademaior, codcidademenor: caractere numveic, numveicmaior,…
-
2
votes3
answers85
viewsA: Why is my Condition Structure assigning a value to a variable?
Note that here: Se (gab[i]=resp[c]) entao variable i has the value it had at the end of the feedback loop. I think it should be: Se (gab[c]=resp[c]) entao You need to assign an incial value to each…
-
2
votes3
answers64
viewsA: when I put a small number in my algorithm it works, but if the number is large the program returns 0
You stated: const long numz = 600851475143; and here does: int i, menor; for ( i = 1; i < numz; i++){ Note that i is an int and an int does not hold this numz value. Maybe you should use long…
-
1
votes1
answer50
viewsA: Select to show clients that are not in another table
What is recommended on this site is you always show what you tried to do and if any error occurred or the obtained result was not as expected. This is not a site to just ask them to do something for…
-
0
votes1
answer53
viewsA: Add hours of all employees during the month
Try: SELECT pessoa.nome, TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(boletins.horaextra))), '%H:%i:%s') AS horaextra FROM pessoa INNER JOIN boletins ON (pessoa.id = boletins.idpessoa) WHERE…
-
-1
votes1
answer193
viewsA: The function should calculate the size of a string, passing a string as a parameter
A possible alternative: #include <stdio.h> #include <string.h> /*Função que verifica tamanho da string*/ int conta_str(char x[]){ int i=0; while (x[i] != '\0') i++; if (i < 8) {…
-
0
votes2
answers939
viewsA: How to compare Select
Try something like: (SELECT TCA.NOM_AVALI ,TCA.DES_CPF, TCB.NOM_AVALI ,TCB.DES_CPF FROM TBL_CONTRATOS_AVALISTA TCA LEFT OUTER JOIN TBL_CONTRATOS_AVALISTA TCB ON (TCA.DES_CPF <> TCB.DES_CPF)…
-
0
votes1
answer69
viewsA: Python reading database postgres
When creating the function: CREATE FUNCTION default is the option SECURITY INVOKER which specifies that the function will be executed with the privileges of the user who called the function. If you…
-
1
votes2
answers55
viewsA: Exercise to sequence numbers with Struct
Try it like this: typedef struct{ int qtdeNumeros; int qtdeRepetidos; float *numeros; }Sequencia; printf("Quantos numeros deseja colcoar na sequencia? "); scanf("%d", &sequencia.qtdeNumeros);…
-
0
votes2
answers72
viewsA: C program does not read values in txt file
Do: void (CPU) { setlocale(LC_ALL, "Portuguese"); int matriz_A[5][5]; int matriz_B[3][2]; int matriz_C[3][2]; char linha[300]; int m, n, k, l, i, j, x, aux; printf("\n Abaixo temos a matriz A \n");…
-
-1
votes2
answers90
viewsA: I’m not getting C. Please help me!
Your code has not been posted complete. Or you declare your variable R with a single character and make the comparison using single quotes: char R; ... while(R!='N' || Nc>0) { ...…
-
1
votes1
answer91
viewsA: Create a recursive function to accuse the occurrence of an element in a matrix
You take this test: if(*(p+ord-1)==num) it is obvious that the else will always be (*(p+ord-1)!=num), it is not necessary to make such a test as it will always be true. It turns out that you put a ;…