MYSQL - Whitespace issue Group by

I am performing UNION while getting the same type of information (company_name, vat, and email) from two different tables (adv and pub). The SQL query is below: SELECT TRIM(UPPER(company_name)), vat, company_owner_email FROM ( (SELECT company_name, v

Rails Group by inside Group by

I need to group my ActiveRecords first by YEAR and then by MONTH, something like this: {2017=> "January"=> [Record1, record2, etc] "February"=> [Record1, record2, etc] 2016=> "January"=> [Record1, record2, etc]

Group by aggregate functions in LINQ

I have a SQL query of the following type and I was trying to fetch the data in my C# application using LINQ select sum(CASE when outcome = 0 then samplingweight else 0 end) tpcount, sum(CASE when outcome = 1 then samplingweight else 0 end) fpcount, s

SUM does not display the expected value in SQL

I have a table as ID TOTAL SUM(TOTAL) 1 62 62 1 53 53 2 62 62 2 47 47 I thought the SUM(TOTAL) should look like ID TOTAL SUM(TOTAL) 1 62 115 1 53 115 2 62 109 2 47 109 This is the query I used select ID, TOTAL, SUM(TOTAL) from tablename GROUP BY TOTA

Two accounts in a motion with opposition where the criteria

I have two separate queries that work fine by themselves but I need them to work in one query. I can combine the results easily enough in excel but this is to be part of a larger query. The two separate queries are: SELECT SiteProductVariation.Produc

PostgreSQL - GROUP BY 10 minutes based on each line

I have a problem difficult to solve, I think you can help. I have a table with millions of records in which precise group every 10 minutes, based on the registry value, for example: Record "01 | 2011/01/03 19:18:00.300" the time it needs to coun

C # gets the number of minutes of the date in the linq group by

I need to group my data by each minute of the day and get the count of the events that occurred during that minute. I currently have: items.GroupBy(x => new {, }) .Select(x => new TransferObject { Minute = x.Key.Minute, Hou

Base sum and group by

I've got a basic SQL query question. I am using SQL Server. I am a complete beginner in SQL. I've got 3 tables. Ultimately, all I want to produce is a list of the 100 hotels (with their ID, name and place) with the most sales. So I know I need to gro

SQL Query-Group by and filters

I have the table as shown in below image. I am trying to get the latest status_id, grouped by team_id and based on max of created_date. --Latest status for each team based on created date SELECT * FROM ProductionHistory WHERE created_Date IN ( SELECT

SQL - Group by not grouping as expected

Not giving detailed information about the table structure and the data: What might be the reason, that this group by: select c.state, case when age <20 then 'u20' when (age >=20 and age<30 ) then 'o20' when (age >=30 and age<40 ) then 'o30'

shows the line with the group max by with two columns sql

lots of variations of this questions have been asked but can't seem to find the right one for my table. i have three columns pd, stm, and salesincrease. i want to find the max of salesincrease for each stm. pd stm salesincrease Chamomile Central 801

MySQL left the subquery to group by

I have a requirement where I need o group data into equal number ob rows. As mysql doesn't have rownum() I'm simulating this behaviour: SET @row:=6; SELECT MAX(agg.timestamp) AS timestamp, MAX(agg.value) AS value, COUNT(agg.value) AS count FROM ( SEL

Calculate the most popular newspaper for each person

I have tables: Persons (person_id, person_name) Newspapers (newspaper_id, nespaper_title) Orders (person_id, newspaper_id, time, price) I need a report, that will show columns: (person_name, most_popular_newspaper_title) Example: +----------+------+-

Mysql Group at 24-hour intervals

How can I Group the records of the table Test by time interval, beginning everyday at 19:00 and ending on the next day at 18:59? Table: Test id creation_date name 1 2014-01-01 17:52:27 a 2 2014-01-01 18:50:00 b 3 2014-01-01 19:00:00 c 4 2014-01-03 18

Select a group by the same table

I have a table users like this: id user refid 1 a null 2 b 1 3 c 1 4 d 2 5 f 3 I need to select the users, grouping by refid and the count of each refid for each user. For example, id user count 1 a 2 2 b 1 3 c 1 This is what I have tried: SELECT use

Mysql Query with group by and case when

Suppose I have three tables like this in MySQL DataBase. 1. User(userId,name)2. Role(roleId,role)3. UserRoleMap(userRoleId,userId,roleId) One User may have multiple roles. In case when user have more than one role, I have to choose one role which com

How can I group an array of objects by month?

I'm using JavaScript. I have an array that contains data in this format: [ {"USER_NAME":"User1","LAST_SUCCESSFUL_CONNECT":"1373978337642"}, {"USER_NAME":"User2","LAST_SUCCESSFUL_CONNECT"

group by but still displaying all the data?

i wonder how to using group by but still displaying full data? i just want to group it. here i give an example of my table : this is my query : (SELECT dp.menu_paket,d.id_detail,t.no_meja,m.nama_menu,d.jumlah,t.status,t.nama_pegawai FROM menu m join

COUNT is incorrect when grouping?

I am trying to display the employee number of each employee who manages other employees with the number of people he or she manages with the below table called emp. empno ename job mgr hiredate sal comm deptno ----- ------ ---------- ---------- -----

SQL Server with left join / having sum / group by

Table B holds planned values. Table M hold actual values. I need to find all rows in table B where either there is no actual values (ie. joined) row in table M, or where joined rows have different total actual value rows. I am trying a combination of

How to make a request to GROUP BY x DESC

The following SELECT statement select * from messages where receiverID = '5' group BY senderID order by id DESC database: id | senderID | receiverID | message 1 | 245 | 5 | test 1 2 | 89 | 5 | test 2 3 | 79 | 5 | test 3 4 | 245 | 5 | test 4 5 | 245 |

Oracle group for too long