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
-
1
votes2
answers602
viewsGroup by Day in Django
Does anyone there have an example of a "bat-ready" grouping by date? I tried all this here... Subscription.objects.extra(select={'day':…
-
1
votes0
answers108
viewsProblem with aggregation function, using Hibernate Createquery
In a Package, a fkEmbaling refers to the 'father', the larger package. EX: Let’s say that 10 A packs fit inside a B package. A packaging record A will have in its fkEmballing the packaging B in…
-
1
votes0
answers215
viewsSELECT in MYSQL grouped by month, but showing all
I have the following table in MYSQL: cavalo - 2016-01-15 cachorro - 2016-01-16 gato - 2016-02-23 coelho - 2016-02-24 ovelha - 2016-03-21 tatu - 2016-03-22 I wanted to give a SELECT and show that…
-
1
votes1
answer73
viewsMysql GROUP BY - PHP error
I have a query in Mysql that, in the command line and in Mysql Workbench, is bringing the correct values, but when running it in PHP, the function GROUP BY is grouping more than it should! Here is…
-
1
votes1
answer482
viewsHow to order a group in the mysql query?
I’m trying to order a query in the database grouping the information, but this showing the first registered in the database, but I want the last. SELECT * FROM base_rating AS B JOIN historico_rating…
-
1
votes1
answer996
viewsGROUP BY - Display grouped result using WHERE as a condition in the same table - Mysql
I am trying to assemble a query to search results in a table where I need to determine a condition for one column, group by another and Display a third. The database consists of 6 Tables, 5 of which…
-
1
votes1
answer1494
viewsTwo variables and a group by? PHP and MYSQL
I’m making a very simple private chat system (just between two people) with PHP and Mysql, Jquery and HTML/CSS. In the database, the table has the following structure: id (int) remetente (varchar)…
-
1
votes2
answers1162
viewsSQL Group same ID with another condition
I believe it’s a little specific question, because I haven’t found anything related yet. I have a table called contas_produtos, which is a relationship Nxn between the tables contas and the table…
-
1
votes1
answer1642
viewsDoubt in select with group by and Count?
I’m making a SQL in 2 tables in Oracle and would like to group the information according to the job code and also count how many people are in that position. I’m using the following SQL: select…
-
1
votes1
answer241
viewsGroup data from a Query?
I do a GROUP BY in a query result and the result comes this way: I wonder if it is possible to bring together in this way? I wonder if this grouping is best done in PHP or Query and how it can be…
-
1
votes2
answers165
viewsGROUP BY WITH ORDER BY
How to make a GROUP BY in the MySQL respecting the results obtained with the ORDER BY Ex: ID(Primary Key) | nome | codigo | tipo 1 | Item E | 5 | 1 2 | Item D | 4 | 1 3 | Item B | 2 | 1 4 | Item C |…
-
1
votes1
answer119
viewsGrouping values in Django
I’m having a little trouble grouping some information from separate models. For example: I have 3 models, a call Category, another call Group and another call Tools. These tables will get the name…
-
1
votes1
answer114
viewsMYSQL - Latest results when grouped by a certain field
I have the following tables in my MYSQL database USERS table id | login --------------- 1 | usuario1 2 | usuario2 3 | usuario3 Status table id | idUsuario | data | status 1 | 1 | 2018-05-10 10:00:00…
-
1
votes1
answer81
viewsSearch with group by
Suppose the following table records authors' posts on a blog. An author may have several posts. So I have several repetitions of authors in this table of the different posts that he did. How I…
-
1
votes1
answer85
viewsHelp with Querie in Linq C#
I have a message table in the following scheme: Id | osID |Interessado | Remetente | Destinatario | Msg -------------------------------------------------- 1 | 2 |João | João | Maria |bla bla bla...…
-
1
votes1
answer44
viewsHelp with Linq Method using group by Dinâmico
I need to mount a dynamic graph from a filter panel and two fields select that can be crossed. I already have the structure that goes to the graph and how I need to return from backend. In the case…
-
1
votes1
answer68
viewsgrouby of cells of a dataframe returns Error in Eval (substitute (expr), send, Enclos): non-numerical argument for binary operator
I want to calculate the differences between cells in a dataframe of a column. > head(df_benchmark) Date .STOXXR 1 2000-01-03 478.52 2 2000-01-04 459.53 3 2000-01-05 448.19 4 2000-01-06 446.24 5…
-
1
votes2
answers577
viewsGroup three commands into one
My dataframe is called f0219. The following command filters a column of this df called Typorubrica when the code is equal to 2; this filter is assigned to the variable f0219Teto; Then, another…
-
1
votes1
answer464
viewsHow to group a column containing a list in pandas? - Python3
Talk to the guys! I have a problem with pandas who can’t find a solution. I have the following dataset: I wanted to make a group where, for each year, and in each category present that year, it…
-
1
votes1
answer36
viewsThe "date" format disappears after using the "group_by" function followed by "summarise (Mean())" in R
I am working with the following global temperature database: https://drive.google.com/open?id=1nSwP3Y0V7gncbnG_DccNhrTRxmUNqMqa I import the data with the function import() package rio and engrave…
-
1
votes1
answer32
viewsGroup mysql results
Good evening, I need to make a query in the table below: But bring me the result of how many type = E , type = S grouped by month, this result I will play in a chart that will display by month how…
-
1
votes1
answer31
viewsConvert percentage
I’m having trouble converting % my code: select veiculos , qtd , trunc(qtd / sum(qtd) over()* 100, 4 ) PERC from ( select ent_datahora_entrada , veiculos , count(*) qtd from ( select…
-
1
votes1
answer58
viewsHow to count the amount of distinct occurrences in a BD and return
I have 3 tables in a library database. One is the member table, with the age of that member and one PRIMARY KEY. The second table, book, has a PRIMARY KEY isbn and the rest of the attributes authors…
-
1
votes0
answers51
viewsHow to apply Transform to two variables in pandas?
I would like to create a new variable which is the scalar product of two variables in a sub-group of my dataframe. I know that when I want to create a group-level variable, I can use the method…
-
1
votes1
answer54
viewsINNER JOIN sql query with GROUP BY
I have a select that is giving error. The idea is the result show five columns (CODPROD, DESCRPROD, CODLOCAL, DESCRLOCAL, STOCK). I’m extracting four tables (TGFEST, TGFPRO, TGFLOC and TGFGRU) and…
-
0
votes0
answers50
viewsReference a group of ID’s resulting from group_concat
I have a select that returns me the equally repeated lines, along with the total. I need to reference this ID group to pass as argument. The result of my query is the array below. Basically it…
-
0
votes0
answers43
viewsSelecting sets of JPA values
I have the following problem: I have a table with a list of values for a composite key. Following example: ID | ItemCode | Localidade | Preco ---+----------+------------+------- 01 | 001 | 001 | 3.5…
-
0
votes1
answer200
viewsDoubt group by + SUM function
I have a problem putting together a query in my database mysql for attendance at an event. I have a participating table where I have the participant’s information, and I have the attendees' presence…
-
0
votes0
answers259
viewsGrouping SUMS by date in Postgresql
I’m trying to make a pick up the orders totals grouped by date as follows SELECT sum(pit.preco) AS preco, sum(pit.quantidade) AS quantidade FROM cliente c LEFT JOIN erp_pedido ped ON ped.id_cliente…
-
0
votes2
answers621
viewsGroup [group by] SQL Firebird
I wonder if there is a way I can make a query where I can bring fields that are not in my group by. I have the following code: select sum(TAB_FATURAMENTO.vl_item),CLIENTE.insc_cnpj from…
-
0
votes0
answers49
viewsGroup by only returns 1 result
I have a problem with my query in Mysql: SELECT * FROM `campeonatos` INNER JOIN `jogos` ON `campeonatos`.`camp_id`=`jogos`.`campeonato_id` WHERE `jogos`.`inicio` > "2017-10-30 00:00:00" ORDER BY…
-
0
votes1
answer46
viewsOrganize mysql select by month groups
I’m trying to organize a return from my mysql bank in months , ie , so I have groups of months of donations that the site that work receives , I tried so: SELECT * , MONTH( `DataConfirmacao` ) FROM…
-
0
votes1
answer26
viewsGroup By show when not in the table
I have the table below in Mysql: I wanted to search the users that has the color BLUE but does not have the color GREEN, IE, in this table would list me user 3 only, I tried so: SELECT * FROM…
-
0
votes1
answer80
viewsGrouping of lines Group By
I have the following appointment: SELECT distinct CAPA.COD_HOLDING, CAPA.COD_MATRIZ, CAPA.COD_FILIAL, CAPA.ID_NF_ENTRADA, CAPA.NUM_NF, CAPA.DT_ENTRADA, CAPA.DT_EMISSAO, CAPA.COD_CLIFOR, CAPA.COD_UF,…
-
0
votes2
answers45
viewssql records = 0
want to show qtos customers I have in every city this sql works but for example, if in Sao Paulo I don’t have any customer registration, it simply hides the city from my report how do I get zero…
-
0
votes2
answers719
viewsBring repeat records from 3 columns in the same table
I have a table with transport voucher data of my company employees: nome ! valor1 ! valor2 ! valor3 teste1 ! 6.50 ! 0.00 ! 0.00 teste2 ! 4.30 ! 2.80 ! 1.10 teste3 ! 8.40 ! 1.10 ! 0.00 teste4 ! 2.85…
-
0
votes1
answer520
viewsHow to Join with Sum and Group By
I’m trying to do an SQL search using Join between two tables. The first table is a table containing monthly savings values for a given project. Each time someone registers a project on the site, a…
-
0
votes1
answer668
viewsMysql - Sort before grouping
I need to make a selection that brings the last users who logged in, without repeating the names. The problem is that the command below first groups and then sorts: SELECT usuario FROM tab_logins…
-
0
votes2
answers56
viewsSQL sub-consultations with counter
I have a table like this: ++++++++++++++++++++++++++++++++++++++++ + Nome | Cargo | Estado + + ++++++++++++++++++++++++++++++++++++++ + Joao | Estagiário | RJ + + Maria | Analista | RJ + + Thiago|…
-
0
votes1
answer47
viewsJoin two Mariadb SQL queries
Two tables tab_Ord_Ser and tab_Pos_Alb. In two different queries I can know the values but I’m not able to unite them in just one. Are they: SELECT Prazo_Producao as Data, COUNT( `Numero OS` ) AS…
-
0
votes1
answer55
viewsI’m having some problems with GROUP BY
I’m having trouble assembling a select with the GROUP BY. What I want to do is this: I have three tables: bicos idbico, idempresa, idbomba abastecimentos idabastec, idbico, idempresa, valorabastecim…
-
0
votes2
answers690
viewsSQL - group by, Count
Good afternoon, I currently have the following code and result. I would like instead of having this result, to have only one row for each type (column 1), this row being the one whose column 4 has…
-
0
votes1
answer573
viewsMysql SELECT with ORDER BY no GROUP BY
I have a table called contacts, all contacts made on the site are registered on it. There is also a table called status, where the service status of each is stored contact. The question, I need to…
-
0
votes1
answer293
viewsSelect com group by duplo
In Mysql I have a table called contact_status: id | id_contato | detalhamento_id 1 | 1 | 2 2 | 1 | 3 3 | 2 | 4 4 | 2 | 2 5 | 2 | 1 6 | 3 | 2 7 | 4 | 4 8 | 5 | 4 In it is recorded all the contacts of…
-
0
votes1
answer330
viewsConsolidate all columns into one MYSQL row
I’m trying to make a query that groups all the results in one line, that is, that does not bring duplicated results. I’ve used the distinct and the group bybut one of the two has returned what I…
-
0
votes1
answer174
viewsCompare two tables in mysql by grouping the main table and listing the result of the second table
Hello! I will explain from the beginning.. I am comparing the following tables accounts with clientes select uses the user_id to find all customers with same users_id2 on the table clientes as…
-
0
votes2
answers130
viewsHow do I Group Text in Mysql
I’ve tried to find a solution to this case, and I need your help. I have the following table: hora data tarefa 10:00 02/01/19 A 10:00 03/01/19 B 11:00 02/01/19 C Whereas today is 02/01/2019, while…
-
0
votes0
answers33
viewsSQL Server Grouping Conditionally
I have the following problem. I have a relationship between 2 tables (1)Tb_log_relac_nfs and (2)Tb_fat_notafiscal_item. Table 2 is where I write both input and output notes. 1 is one that stores the…
-
0
votes1
answer28
viewsmysql foreign key
someone could help me assemble this query? let’s say I have the following tables: tabela1: aluno (id, nome, cidade) 1 Pedro 2 Joao 3 Joaquim tabela2: cidade (id, municipio) 1 Manaus 2 São Paulo 3…
-
0
votes1
answer331
viewsSelect mysql with COUNT and GROUP BY MONTH
Hello, I am trying to put together the information of two tables to generate a graph, I need to count the total of record consults1 and consults2 and group by month: Currently I have this return:…