group-by

Needing assistance with counting the most different books

眉间皱痕 提交于 2019-12-13 04:37:03
问题 Which customer(s) ordered the most different books? Display the customer id and include ties. This is not talking about the quantity of books ordered. For example, suppose my only orders are Customer 1 ordered 400 copies of book_id 34 Customer 2 ordered 2 copies of book_id 62 and 3 copies of book_id 29 Customer 1 ordered a larger quantity of books but customer 2 ordered more different books. The query should - in this case- return customer 2: Here is my attempted solution. Not sure how to

SQL Statement to eliminate duplicates based on value in another column

帅比萌擦擦* 提交于 2019-12-13 04:33:57
问题 I have data that is in two tables and I have a query combining the data as below. I am trying to eliminate duplicates based on the Id column where I pick the record with the oldest split date. Could anyone kindly assist me with the SQL statement to effect this? |ID |SecID |ReportingDate |SplitDate |Adjustor| |1465 |2 |31-Dec-09 |01-Nov-10 |0.1 | |1465 |2 |31-Dec-09 |27-Dec-12 |0.2 | |1466 |2 |31-Dec-10 |27-Dec-12 |0.2 | |1468 |2 |31-Dec-11 |27-Dec-12 |0.2 | |1469 |2 |31-Dec-08 |01-Nov-10 |0.1

Grouping of top 80% categories

浪子不回头ぞ 提交于 2019-12-13 04:32:34
问题 I need SQL query for grouping by some category which would present quantities of only those groups which in total contain at least 80% of all categories, other rare categories (containing up to 20% of total) should be represented like "other". So the result of such a query for grouping apples by category color should look like this: RED 1118 44% ) YELLOW 711 28% > at least 80% GREEN 229 9% ) other 482 19% How to do that? 回答1: I would do this with a combination of aggregation and analytic

return different lists for each key

孤街醉人 提交于 2019-12-13 04:24:15
问题 I have a table that is parsed in code as a List of string[] (each string[] is a column). Column1| Column2 | Column3 --------+---------+---------- 0 | 1 | 8 3 | 2 | 3 5 | 2 | 8 Let´s say: string[] column1 = { 0, 3, 5 } string[] column2 = { 1, 2, 2 }; string[] column3 = { 8, 3, 8 }; List<string[]> table = new List<string[]>() { column1, column2, column3 }; I want to select a column (i.e. Column1) groupby Column3, and create a list with each different value in Column3. In other words: group

SELECT: Group by function result

让人想犯罪 __ 提交于 2019-12-13 04:05:36
问题 I have a stored function that calculates the status of an entity (this status is NOT an attribute of the entity but needs to be calculated). Within a SELECT statement, I want to know how many elements have which status. For now, I got the following: SELECT my_function(entity_id) AS status, COUNT(*) FROM some_table GROUP BY my_function(entity_id) -- entity_id is a column of some_table ORDER BY status; This works but I find it quite ugly to repeat the function call within the GROUP BY statement

Group by doesn't give me the newest group

ⅰ亾dé卋堺 提交于 2019-12-13 04:03:10
问题 I was trying to get the distinct result from my table, and people said I should use the group by. This worked half way... I now get the distinct result but the result is not the newest thread... my table contains status on apartments from several buildings. The apartments can be found many times since it's a history table... I need to make a select that retrieves the distinct apartments with the current status. ID Building Apartment_id Status 1 1 1 1 2 1 1 2 3 2 2 3 4 2 4 2 5 2 3 2 6 2 5 1 7

How can I add to my list empty objects based on week number

﹥>﹥吖頭↗ 提交于 2019-12-13 03:56:23
问题 I'm getting data from db like this: Later I group them so it looks like Month 6 Week 2 Amount 228 And so on.. Here is the code: var yas = await _context.product .AsNoTracking() .Where(x => (x.PaymentDate != null && x.PaymentDate > DateTime.UtcNow.AddMonths(-4))).ToListAsync(); var grouped = yas.GroupBy(x => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(x.PaymentDate ?? DateTime.UtcNow, CalendarWeekRule.FirstDay, DayOfWeek.Monday)) .Select(product => new productsDemoObject { Week =

Counting rows in event table, grouped by time range, a lot

自古美人都是妖i 提交于 2019-12-13 03:51:09
问题 Imagine I have a table like this: CREATE TABLE `Alarms` ( `AlarmId` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT "32-bit ID", `Ended` BOOLEAN NOT NULL DEFAULT FALSE COMMENT "Whether the alarm has ended", `StartedAt` TIMESTAMP NOT NULL DEFAULT 0 COMMENT "Time at which the alarm was raised", `EndedAt` TIMESTAMP NULL COMMENT "Time at which the alarm ended (NULL iff Ended=false)", PRIMARY KEY (`AlarmId`), KEY `Key4` (`StartedAt`), KEY `Key5` (`Ended`, `EndedAt`) ) ENGINE=InnoDB; Now, for a GUI, I

How to do group-By using custom pipes in angular

可紊 提交于 2019-12-13 03:46:15
问题 I am trying to group by my list of an array by date using below code but it's not working and just showing group by date but not showing related child data I do not understand where did I do a mistake and I am a learner and I follow http://www.competa.com/blog/custom-groupby-pipe-angular-4/ link for doing my requirement home.ts: events: any; constructor(public navCtrl: NavController, public navParams: NavParams) { } ionViewDidLoad() { this.events = [{ id: 1, category:'camera', title: 'First

group rows into columns with sum [duplicate]

这一生的挚爱 提交于 2019-12-13 03:44:29
问题 This question already has answers here : How can I return pivot table output in MySQL? (8 answers) Closed last year . Let say we have this table: CREATE TABLE `table1` ( `Name` CHAR(50) NOT NULL, `Type` CHAR(50) NOT NULL, `Value` DOUBLE NOT NULL ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB; --------------------------------- | Name | Type | Value | --------------------------------- | Dep1 | Cash | 100 | --------------------------------- | Dep1 | Card | 200 | --------------------------------- |