Questions tagged as 'group-by'

1
answer

Group two fields in the same table with mysql

I'm trying to set up a query, where I can print out the broker's name and the percentage of the sale pertaining to it. When grouping by name_corretor1, the field name_corretor2 does not group and vice versa, when grouping both the grouping is no...
asked by 08.04.2016 / 18:56
1
answer

Best approach is to filter data in the database or application?

Suppose we have a 'Vendas' table with the following 'estado', 'cidade', 'vendedor', 'valor' columns. 'estado' and 'cidade' would be where the sale was made and 'vendedor' would be what made that sale. 'v...
asked by 07.06.2017 / 19:45
1
answer

Sql query return same name with different date

My table Acidente looks something like this: Vitima - DataRegistro Pedro - 10/02/2015 Pedro - 20/03/2015 Maria - 01/05/2015 Maria - 01/05/2015 I need to make a query (Sql) that returns the records that contain: Victim's name...
asked by 22.06.2015 / 03:41
1
answer

Search with group by

Suppose the following table that records author posts in a blog. An author can have several posts. So I have several reps of authors on this table of the different posts he made. How do I make a query to fetch the content of the most re...
asked by 23.09.2018 / 05:54
1
answer

GROUP BY - Display grouped result using WHERE as condition in same table - MySQL

I'm trying to set up a query to fetch results in a table where I need to determine a condition for one column, group for another, and display a third. The database is composed of 6 tables, 5 of which are queried individually, containing: i...
asked by 04.01.2017 / 00:08
1
answer

Doubt in select with group by and count?

I'm doing 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 charge. I'm using the following SQL : select f.numemp, f.numcad, f.nomfu...
asked by 03.05.2017 / 20:55
2
answers

Group by two fields ordered by a third party

I have the following data: |--------------------------------------------------------| |USER | ID | DEVICEID | DATE | |--------------------------------------------------------| |7 | 14450 | aa6603ceef3b397c | 2...
asked by 03.08.2016 / 15:34
1
answer

SQL: Can I have clauses in GroupBy that do not appear in Select?

I know that I can not have clauses in the select that do not appear in Group By. But is it possible otherwise? For example: Select B From Table Group By A,B     
asked by 10.05.2015 / 03:36
1
answer

Using Group By in SAS Guide

I'm having trouble using the command GROUP BY , in SAS . By definition, SAS only accepts GROUP BY if a summary function is used in SELECT . Until then, okay. Turning Proc below, the result exits correctly: proc sql; c...
asked by 31.07.2014 / 17:35
1
answer

How to sort a group in the mysql query?

I'm trying to sort a query in the database by grouping the information, however this is showing the first one registered in the database, but I want the last. SELECT * FROM base_rating AS B JOIN historico_rating AS H ON B.id = H.id_base_rating...
asked by 28.08.2017 / 20:20