group-by

MySQL ORDER BY or GROUP BY [duplicate]

早过忘川 提交于 2019-12-13 10:07:37
问题 This question already has an answer here : MySQL SELECT and ORDER BY [closed] (1 answer) Closed 6 years ago . In relation to: MySQL ORDER BY Customized I have another question. We have an id_competitor with various scores. id_competitor score 1 WIN 2 50+ 3 90+ 4 90+ 1 50 2 WIN 3 40 4 40+ I would like to use order by but in the following order: id_competitor 2 1 4 3 I dont know how i should do it, with SELECT DISTINCT with ORDER BY or GROUP BY 回答1: based on other answer, I would do something

Problems with grouping

半腔热情 提交于 2019-12-13 09:36:03
问题 How do i get an output like this where i can suppress duplicates in the company name row?.. Example output: Ref Company name Total calls Last name Calls No call ----- ------------------- ----------- ------------ ---------- ------- 135 Dasher Services 12 Clarke 5 Wright 4 Turner 3 142 Diaphonic Shipping 12 Hill 5 Johnson 5 Butler 2 Jackson 0 ******* 107 Juan and Co. 12 White 4 Turner 3 Clarke 3 Roberts 2 Query: SELECT CUSTOMERS.CUSTOMER_ID AS REF, CUSTOMERS.COMPANY_NAME, COUNT (CALLS.CALL_REF)

MySQL GROUP BY not working as expected

别来无恙 提交于 2019-12-13 09:30:03
问题 I have written a series of nested procedures which perform some pay calculations for employees. Throughout these procedures data is stored in temp tables. Now the issue is some unexpected behaviour when I perform a GROUP BY on one of these temp tables. You can see an example of that step here: http://www.sqlfiddle.com/#!9/f4095/2 The expected behaviour is for that GROUP BY to output a list of employeeid and the corresponding aggregations. The sqlfiddle works as expected. However, what is

How to sum and group values using MySQL ?

ぐ巨炮叔叔 提交于 2019-12-13 09:13:37
问题 I was wondering how to sum and group values using MySQL. Now thats simple, however I have a bit of an odd situation. I have a table that allows users to insert the amount of cigaretes smoked every day, what I am trying to do is sum the data for every day . Anybody has any ideas how with php or mysql I could sum the data of cigaretes smoked per day and group it by day ? 回答1: SELECT SUM(how_many) AS per_day, `date` FROM cigaretes GROUP BY DATE(`date`) 来源: https://stackoverflow.com/questions

ORACLE SQL Group By STILL giving Duplicates

大城市里の小女人 提交于 2019-12-13 08:59:01
问题 Have been working on this the whole day. Following query returns around 162,000 records. Handful of them are duplicates. Really, I'm not sure how else to troubleshoot. This database pulls from external database for which I only have READ Access. For example, if I have two rows 20684 2/26/2019 11:13:04 AM abra 123 abc 6 abra 20690 2/26/2019 11:13:04 AM abra 123 abc 6 abra I would like to keep 20684 abra 123 abc 6 abra 20684 is the unique I.INCIDENTID that is not included in GROUP BY` Please

jq: groupby and nested json arrays

旧街凉风 提交于 2019-12-13 08:29:30
问题 Let's say I have: [[1,2], [3,9], [4,2], [], []] I would like to know the scripts to get: The number of nested lists which are/are not non-empty. ie want to get: [3,2] The number of nested lists which contain or not contain number 3. ie want to get: [1,4] The number of nested lists for which the sum of the elements is/isn't less than 4 . ie want to get: [3,2] ie basic examples of nested data partition. 回答1: Since stackoverflow.com is not a coding service, I'll confine this response to the

GROUP_BY WITH DISTINCT QUERY

旧时模样 提交于 2019-12-13 07:59:07
问题 Am using Oracle 12c, below is the column: CENTER_ID UNIT EMPLOYEEID LESSON MINS_STUDIED SECTION I234 4 G01234 4.1 5 EX I234 4 G01234 4.1 5 LN I234 4 G01234 4.1 5 VO I234 4 G0123 4.2 5 EX I234 4 G0123 4.2 5 LN I234 4 G0123 4.2 5 VO I2345 5 G023 5.2 12 EX I2345 5 G023 5.2 12 LN I2345 5 G023 5.2 12 VO From record 1 to 6, it contains 2 distinct employee_id who studied unit 4. In this case, I need total minutes spent per unit (center_id wise). But I want to add only distinct MINS_STUDIED based on

using combination of select, union and group by

岁酱吖の 提交于 2019-12-13 07:54:59
问题 I have two similar tables and a third table with one shared column (sms_status_id) with first and second table. I want to select similar columns from first and second table, union them with third table and then remove repetitive rows. This is what I've done so far: select * from ( select sms_log_id, atm_id, device_id, error_id, datetime, retries, message from first_table join third_table on sms_log_id = sms_status_id ) union ( select sms_id, atm_id, device_id, error_id, datetime, retries,

My where clause doesn't apply on my result

让人想犯罪 __ 提交于 2019-12-13 07:52:57
问题 I have this query _ctx.TestPackageReportDetails.GroupBy(i => new {i.Status, i.TestPackageId}) .Where(m => m.Count(i => i.Status == "Accept") == 5) The result : And this query : var q2 = _ctx.TestPackages.ToList(); Now i create a join between two result : _ctx.TestPackageReportDetails.GroupBy(i => new { i.Status, i.TestPackageId }) .Where(m => m.Count(i => i.Status == "Accept") == 5) .Join(_ctx.TestPackages, i => i.Key.TestPackageId, m => m.Id, (i, m) => new { pack = m, det = i }) .Sum(i => i

Groupby max value and return corresponding row in pandas dataframe

六眼飞鱼酱① 提交于 2019-12-13 07:40:39
问题 My dataframe consists of students, dates, and test scores. I want to find the max date for each student and return the corresponding row (ultimately, I am most interested in the student's most recent score). How could I do this in pandas? Let's say my dataframe looks like this (an abbreviated version): Student_id Date Score Tina1 1/17/17 .95 John2 1/18/17 .8 Lia1 12/13/16 .845 John2 1/25/17 .975 Tina1 1/1/17 .78 Lia1 6/12/16 .89 This is what I want: Student_id Date Score Tina1 1/17/17 .95