Most voted "group-by" questions
GROUP BY is a standard SQL relational database command for collapse result lines that share a common field value on a single line. Aggregation functions can be performed in other group fields, such as SUM() or AVG(), to gather related data into a single value. also used in other languages like Linq.
Learn more…125 questions
Sort by count of
-
0
votes1
answer32
viewsGroup By com sql server
I am trying to group the data of my select , according to the field C9_CARGA , however when I run this select it returns me without being grouped , I believe I am doing something wrong . How are you…
-
0
votes1
answer59
viewsProblems with Group By on Postgresql
I’m trying to make a view in a Postgre database: 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…
-
0
votes1
answer370
viewsGroup by com Python[Nympy or Pandas] - Bring the 1st line and last line by date
Good afternoon forum colleagues. I’m having a hard time bringing the 1st line and the last row grouped by date. However, I would like to bring this data in the format I am using group By in sum or…
-
0
votes1
answer260
viewsMultiply two columns in a select With Groupby
How Can I Do This Multiplication? the table looks like this: What has to be done is to group disciplines 11 and 13, count how many 'sit' F and Null have and multiply by 'qntd_aula'... I managed to…
-
0
votes2
answers44
viewsDoubt group by oracle
I want to do a group by between two tables by doing an Inner Join. The employee table and the table employed at the post. I want it to return to the most recent entry into a post of a given…
-
0
votes5
answers97
viewsDoubt with Select using ORDER BY
I’m trying to make a SELECT so that it displays from the second table only the most recent record. I tried to do it using GROUP BY and ORDER BY, but with the GROUP BY mine SELECT does not work, only…
-
0
votes1
answer37
viewsTotalize products through two tables - Mysql
I wish the result of SELECT to return: Product name | Credit | Debit | Balance Badge 076 |10 | 5 | 5 Badge 064 | 20 | 10 | 10 Table: products [product.id / product.name] Table: badges [badges.id /…
-
0
votes0
answers146
viewsHow to group by column only when it is not null (Oracle)?
The query is summarized to facilitate: SELECT nome,idade,profissao,cidade, bairro, estado, pais FROM objeto group by nome,idade,profissao,cidade, bairro, estado, pais; However 3 columns can come…
-
0
votes1
answer28
viewsDynamically merge lines that share the same key into one
I have a Dataframe. I would like to make another column that combines columns whose name starts with the same value in Answer and QID. That is, with this Dataframe exercise: QID Category Text QType…
-
0
votes4
answers68
viewsDoubt about Group by
using SQL Server I have made the following select to select products purchased by customers: select ITEMPEDIDO.IDPEDIDO, ITEMPEDIDO.QUANTIDADE, CLIENTE.NOME from ITEMPEDIDO, cliente, pedido where…
-
0
votes0
answers47
viewsMYSQL - Query, Find last values of a database based on the day and time of the record with an Inner Join
good afternoon... I need a help from the noble programmers of this forum to solve a small bug (I say I’m not a programmer, I’m curious). I have 2 databases, the first database is dynamic, it…
-
0
votes2
answers285
viewsHow to bring more fields in the Pandas groupby, without necessarily having to use them in the grouping?
Good afternoon, guys. I’m messing with the Pandas library in Python and I’d like to ask you a question, if possible. I have a list of values and need to reduce this list to just one record per date.…
-
0
votes1
answer39
viewsgroup each period per month
I’m doing this consultation, but I’m not able to group each period per month, the previous year. For each month of the year preceding the current year, return the amount of parked cars per period…
-
0
votes2
answers63
viewsIs there any way pd. Grouper, how much used for time frequencies, adds lines even when there are no records in a time interval?
I need to merge between two tables where the base table is grouped at 5 minute intervals, however in an interval that has no record to be grouped the corresponding row is not created I am dealing…
-
0
votes2
answers74
viewsMysql - Catch minor record in a 1:N ratio
Good evening, I may have this answer somewhere but I spent all day researching, using various examples and nothing. I have 2 tables, one of products and another with the models being that 1 product…
-
0
votes1
answer25
viewsHow to verify if an ID has different information in a period of time?
I have the following database: cnpj_root, affiliate (1 = matrix, 2 = affiliate), Uf, active_em_2017, active_em_2018, active_em_2019, active_em_2020 (NA= inactive, 1 = active). What I need: identify,…
-
0
votes0
answers31
viewsHow do I Compare fields from different tables using HAVING
I’m trying to make an SQL query in Firebird where it will only return data if the sum of the fields in the first table is different from the Field "vlrnota" of the second table. However, when trying…
-
0
votes0
answers23
viewsHow to sum the columns without multiplying the sums?
When I run this query it sums the columns several times in the same number of outputs in the table itemsaida. select p.idproduto codigo, p.descricaoproduto nome, sum(e.qtde) entrada, sum(s.qtde)…
-
0
votes1
answer20
viewsGroup By of 1 Oracle SQL Column with latest date
I have a table (TVIC_ODS_MVEL_PRQE), in ORACLE SQL, with millions of records and need to extract from it only 2 columns: phone number (NU_TLFN) and date (DT_PRMR_ATVC_LNHA). The problem is that I…
-
-1
votes1
answer143
viewsTake the lowest values of a Count using group by
Cheers guys, I have the following problem... The query below is almost perfect, but it is generating repeated Ids, what I need is the lowest Count value of each ID. The ideal result would be: ID |…
-
-1
votes1
answer43
viewsShow records, via PHP and Mysql query, in two tables, with GROUP BY
Good evening... I have the following doubts This system aims to bring users from a particular region or workplaces that belonged to a particular city. If we search for city=4261, according to the…
-
-1
votes1
answer28
viewsQuestions with COUNT/GROUP BY
Good afternoon, I’m having trouble with the group by clause. I have a gigantic query, I need to quantify the contracts by Id, showing the degree of impact. Then I gave a Count(Id). The problem is…
-
-2
votes1
answer221
viewsHow to join files into folders, based on their prefixes?
I have in hand thousands of files that have common prefixes in their names, something like: [Example of prefix 1] ABC-1.mp4 ABC-2.mp4 ABC-3.mp4 [...] ABC-999.mp4 [Example of prefix 2] AAA-1.mp4…
-
-2
votes1
answer570
viewsGroup By with Sequelize
I have the following class structure: I’m trying to group and count Sequelize how many titles each selection had from the table Cup_Selections same as the query typed below: My Node consultation…
-
-3
votes1
answer102
viewsA - Adding values with one condition
Good morning ! I have the DF below, I need to add the values of the accounts (columns with numbers) SEMESTER 1 with the 2 (if you have), by CNPJ and YEAR. Thus, I will have the total values of the…