Posts by anonimo • 4,084 points
322 posts
-
0
votes1
answer44
viewsA: Transform and return a centered string s into a length width string
First you need to calculate how many positions you have to fill. Fill in half copy the string and fill in the remaining positions. #include <stdio.h> #include <string.h> char *…
-
3
votes1
answer32
viewsA: Group mysql results
If I understand correctly, I believe: SELECT DATE_FORMAT(`date`,'%b') AS `mes`, SUM(CASE WHEN Type = 'E' THEN 1 ELSE 0 END) AS TypeE, SUM(CASE WHEN Type = 'S' THEN 1 ELSE 0 END) AS TypeS FROM…
-
1
votes1
answer83
viewsA: How to print only vowels contained in a string?
Although printing the requested result you did not set a function. Try: def vogais(str): for c in str: if c in 'aeiou': print(c) vogais('univesp')…
-
2
votes1
answer32
viewsA: Select Same Field
If I can understand what you want maybe: select c.empresa, p.nome, SUM(CASE WHEN OrdemAut = 'N' THEN 1 ELSE 0 END) as 'Com cotação', SUM(CASE WHEN OrdemAut = 'S' THEN 1 ELSE 0 END) as 'Sem cotação'…
-
1
votes1
answer62
viewsA: algorithm to read age years, months, and years and convert the value to age only in days
You have to accumulate and at the end print the amount of days. #include <iostream> using namespace std; int main() { int anos, meses, dias; cin >> anos >> meses >> dias;…
-
0
votes1
answer26
viewsA: MYSQL how to query in 2 tables where the query may or may not exist in one of the tables?
If understood correctly use a junction. SELECT * FROM bemtbgeral AS tb1 LEFT OUTER JOIN gruposusercentral AS tb2 ON (tb2.idgrupo = tb1.idgrupo) WHERE tb1.caduser = '".$_SESSION['iduser']."' OR…
-
-1
votes1
answer128
viewsA: Calculate pi with the python sequence
A possible solution is: n = 1 resultado = 0 sinal = 1 while True: termo = sinal * (4.0 / n) if termo < 0.00001: break resultado += termo n += 2 sinal = -sinal print(f'{resultado}')…
-
0
votes1
answer29
viewsA: Query output in mysql grouping
Use the GROUP_CONCAT aggregation function. Correcting field name in GROUP BY: SELECT r.nregion, GROUP_CONCAT(t.idusrec SEPARATOR '-') FROM tb_tree t INNER JOIN tb_regioes r on t.idreg = r.idreg…
-
0
votes1
answer20
viewsA: NOT IN/EXISTS in more than one table in the same query
Although the modeling is very strange try: SELECT empregado.cod WHERE NOT EXISTS (SELECT cod FROM arquiteto WHERE empregado.cod = arquiteto.cod UNION SELECT cod FROM paisagista WHERE empregado.cod =…
-
0
votes2
answers161
viewsA: Terminate program with enter/ EOF
Try something from the guy: #include <stdio.h> int main() { int n1=0, n2=0, sum; do{ sum = n1 + n2; printf("%d\n", sum); } while((scanf("%d %d", &n1, &n2) != EOF)); return 0; }…
-
0
votes1
answer39
viewsA: How to perform this query correctly ? [Mysql]
A way would be: SELECT Companhia.codigo_companhia, Companhia.nome_companhia, Companhia.cidade, COUNT(Trabalha.matricula_empregado) AS Qtde FROM Companhia INNER JOIN Trabalha ON…
-
0
votes2
answers34
viewsA: Logic for SQL statement - Sum of values between Table A and Table B
Would not be: SELECT tabela_B.descricao FROM tabela_B INNER JOIN tabela_A ON (tabela_A.descricao = tabela_B.descricao) GROUP BY tabela_A.descricao HAVING SUM(tabela_A.valor) < tabela_B.valor…
-
0
votes1
answer37
viewsA: HELP WITH CODE IN C, STRINGS
Using the string definition in C, a possible solution is: #include <stdio.h> void main (){ char string[50]; printf("String inicial: "); scanf("%s", string); printf("String final: "); for (int…
-
0
votes2
answers120
viewsA: Mysql - Select - how to group two different values into a single value
See if it answers: SELECT monthname(o.processed_timestamp) AS Mês, SUM(CASE o.status = 'confirmado' THEN 1 ELSE 0 END) AS confirmado; SUM(o.status ='recusado' OR o.status = 'naoconfirmado' THEN 1…
-
1
votes2
answers32
viewsA: Query that returns sum where states are equal to X and other clusters
One possibility is to use CASE / WHEN: SELECT SUM(CASE WHEN estado = 'SP' THEN Vendas ELSE 0) AS SP, SUM(CASE WHEN estado = 'RJ' THEN Vendas ELSE 0) AS RJ, SUM(CASE WHEN estado <> 'SP' AND…
-
1
votes1
answer424
viewsA: UPDATE with 2 Joins POSTGRESQL
Postgresql does not use this type of syntax. Try: WITH t AS ( SELECT proced_conv.cd_convenio, proced_conv.vl_unitario_bras * c.ajuste_porcent / proced_conv.fator_ajuste AS val FROM proced_conv INNER…
-
0
votes1
answer30
viewsA: Family struct problem in c
I think you misunderstood my comment. Try: Whereas brothers are those who have the same father and same mother: printf("\nIrmãos\n"); for (i=0; i<NUM-1; i++) { for (j=i+1; j<NUM; j++) { if…
-
0
votes1
answer46
viewsA: How do I merge into two array, but toggle them. (python)
One way is to initialize the resulting array as empty and append each element of the initial arrays alternately. array0 = [1,2,3] array1 = ['a','b','c'] array2 = [] for i in range(3):…
-
-1
votes1
answer35
viewsA: Problem with C program
A small change in your program improves this solution: #include <stdio.h> #include <stdlib.h> int main() { int vet[20], x, repete; for(int i = 0; i < 20; i++) { printf("Digite um…
-
1
votes1
answer43
viewsA: Mysql - A single entity (N:N)
This is called self-relationship. Note that the table tb_natural_person must participate in his SELECT two-part: parent and child. I think what you want is something like: SELECT * FROM…
-
0
votes2
answers860
viewsA: Media calculation using C++ Function
Correcting average calculations and removing choice duplicity. #include<iostream> #include<cstdlib> using namespace std; float calc_media(float n1, float n2, float n3, int tipo) { float…
-
0
votes2
answers156
viewsA: Birthday Ordering - SQL Server
If it’s just the birthdays that will happen from now on try: SELECT * FROM TabelaX WHERE MONT(Aniversario) * 100 + DAY(Aniversario) > MONTH(getdate()) * 100 + DAY(getdate()) ORDER BY…
-
0
votes1
answer54
views -
1
votes1
answer32
viewsA: Resolve this database issue
With INNER JOIN you only recover what exists in the two tables, ie only those that carried out some commercialization. In your case use LEFT OUTER JOIN: SELECT CR.nome, (CASE WHEN…
-
1
votes1
answer109
viewsA: Two SUM functions in Oracle SQL to return two different sums with two SELECT
Don’t use UNION because it serves to get data exactly the way you posted and that doesn’t suit you. Try: SELECT COD_REPRESENTANTE, REPRESENTANTE, TOTAL_FATURAMENTO, TOTAL_PEDIDO FROM (SELECT…
sqldeveloperanswered anonimo 4,084 -
0
votes1
answer40
viewsA: Bring manager and employee who are on the same table
If I understand correctly it is enough only the EMPLOYEES table participate with two roles: EMPLOYEES and MANAGER: SELECT --SEQ_DADOS_CADASTRAIS.NEXTVAL, --SYSDATE, PAN.ATSF_NOME, GESTOR.ATSF_NOME…
-
0
votes1
answer22
viewsA: Problem in queries N : N
Just add the table with the proper joining condition: SELECT produto.nome AS 'Produto', fabricante.nome AS 'Fabricante', fornecedor.nome, fornecedor.email FROM produto JOIN fabricante ON…
-
1
votes1
answer36
viewsA: Program that calculates a series of N terms
In this passage: for i in range(0, n + 1): for j in range(1, n + 1): s = s + (i / fatorial_for(j * 2)) does not make sense this second loop. Use: for i in range(0, n + 1): s += i / fatorial_for(i *…
python-3.xanswered anonimo 4,084 -
1
votes1
answer1170
viewsA: Visualg algorithm over prime numbers in a repeat structure
There’s no point in you doing: para c de n1 ate n2 faca ... para i de n1 ate c faca Another thing is that cmod is the name of a variable and c modyou are utilizing the rest of the division operator.…
-
0
votes2
answers72
viewsA: Select all months of the year in postgres
The generate_series function together with LEFT OUTER JOIN can be very useful: SELECT foo.data, COALESCE(SUM(valor), 0) valor FROM generate_series('2020-01-01'::date, '2020-31-12'::date, '1 month')…
postgresqlanswered anonimo 4,084 -
0
votes1
answer52
viewsA: SQL grouping
I believe that what you want, and what you have tried to explain in the comments, is: SELECT TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.APELIDO, TV.AD_CARTAOCAMP, SUM(TP.AD_CAMPLENTE),…
-
1
votes1
answer229
viewsA: SELECT with two Foreign key, return the two tables even looking for only one of the keys
For your explanations that what you want is: SELECT "Proposta".id, "Proposta".id_segurado, "Proposta".data_implantacao, "Proposta".data_assinatura, "Proposta".status, "Segurado".documento,…
-
1
votes1
answer37
views -
1
votes1
answer22
views -
1
votes3
answers69
viewsA: Break query result in 2 lines
Separate your joints and make a union of two Selects: select b.* from portal_sega_user a -- perfil inner join portal_sega_user b -- secretaria secundaria on b.USUARIO = a.SECRETARIAPRINCIPAL where…
-
2
votes1
answer423
viewsA: Remove white space in select (SQL)
Use the TRIM function: SELECT id FROM BAIRRO WHERE TRIM(NOME) LIKE 'Areao' ; https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_trim…
-
0
votes1
answer25
viewsA: Mysql - Cross-table information (Selects)
From what I understand: SELECT * FROM (Albuns INNER JOIN Capas ON (Albuns.id2 = Capas.id2)) LEFT OUTER JOIN (Compras INNER JOIN Clientes ON Compras.id4 = Clientes.id4) ON (Albuns.id1 = Compras.id1)…
-
0
votes1
answer100
viewsA: Does anyone know how it is possible in postgresql, I have two tables with column type ARRAY and use WHERE, to select the records by this column?
If in both tables you have a field called GROUPS and want to know which lines have the GROUPS field element(s) in common then use the && (overlap): SELECT * FROM tab1 INNER JOIN tab2 ON…
-
0
votes1
answer267
viewsA: Exercise with counter problem
After reading you need to test if the salary is non-negative. #include <stdio.h> #include <stdlib.h> int filhos=0, contador_pessoas=0, contador_pessoas_100=0; float salario=0,…
-
1
votes1
answer28
viewsA: Memory allocation problem, with large values
From what I understand of the problem, and guiding me by the principle KISS, I would do: #include <stdio.h> #include <stdlib.h> int main() { int tam, casos, ocor, num, *vet, i, j, k, l;…
-
3
votes1
answer123
viewsA: Ideal Weight Exercise (Language C)
Just direct test and print the message. #include <stdio.h> #include <stdlib.h> char sexo, sair; float peso, altura, diferenca, pi, situacao1, situacao2; main() { do{ printf("Digite o seu…
-
0
votes2
answers148
views -
-3
votes1
answer172
viewsA: Create a vector with srand without repeating numbers in C
Draw on this: #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int numero[50], i, j; char ja_consta; srand(time(NULL)); for (i=0; i<50; i++) { numero[i] =…
-
0
votes2
answers64
viewsA: Repeat odd numbers with do while
In this particular case it could simplify to: case '3': { impar0a200 = 1; cout<<"\n Os números a seguir são os ímpares entre 0 e 200: " << endl; do { cout << "\t" <<…
-
5
votes1
answer44
viewsA: How to define the same INNER JOIN for different fields related to the same table
From your explanation it seems to me that what you want is: SELECT solicitante.nome_usuario, autorizador.nome_usuario FROM portaria INNER JOIN usuarionportaria_solicitante as ups ON…
-
2
votes1
answer81
viewsA: replace drop by loop
The use of goto is a bad idea. Just use a repeat loop. #include<stdio.h> #include<stdlib.h> int main() { int p1, s2, s3; do { system("clear"); printf("Digite:\n[1] Para acessar o…
-
1
votes1
answer30
viewsA: Query with a different filter for each line
If I understand, try: SELECT COUNT(CASE WHEN (duplicata_comment = '%restri%') THEN 1 ELSE 0 END) cont_restricao, SUM(CASE WHEN (duplicata_comment = '%restri%') THEN…
-
-1
votes1
answer62
viewsA: Database - Mysql - Relationship between tables / INNER, LEFT, RIGHT JOIN
It seems to me what you want is: SELECT * FROM tb_pessoas INNER JOIN tb_clientes ON tb_pessoas.idpessoa = tb_clientes.idpessoa INNER JOIN tb_agendar ON tb_clientes.idcliente = tb_agendar.idcliente…
-
3
votes1
answer40
viewsA: Doubt about accounting for ' n' in C
You are reading twice. Use getc only in while and save the result in a variable. Inside the test loop this variable. include < stdio.h > include< stdlib.h > int main(void) { int cont =…
-
-2
votes1
answer48
viewsA: Make SELECT return only a snippet of the string
If I understand your question correctly: SELECT COUNT(*) FROM sua_tabela WHERE seu_campo LIKE '%hig%';