group-by

MySQL JOIN with where clause and group by count

[亡魂溺海] 提交于 2020-01-06 11:56:49
问题 I run a the following query, SELECT status.status_id, status.status_name, COUNT(workbin.status_id) FROM `status` LEFT JOIN `workbin` ON workbin.status_id = status.status_id GROUP BY status.status_id and got the output status_id status_name count 1 New 44 2 On Hold 1 3 In Analysis 2 4 In Development 12 5 In Testing 17 6 In Release 2 7 Completed 151 8 In Review 0 9 Unit Testing 0 11 Rework 0 12 Reopen 0 Now i need to add a where clause in this query, to retrive the data based on the user id in

MySQL JOIN with where clause and group by count

你。 提交于 2020-01-06 11:55:27
问题 I run a the following query, SELECT status.status_id, status.status_name, COUNT(workbin.status_id) FROM `status` LEFT JOIN `workbin` ON workbin.status_id = status.status_id GROUP BY status.status_id and got the output status_id status_name count 1 New 44 2 On Hold 1 3 In Analysis 2 4 In Development 12 5 In Testing 17 6 In Release 2 7 Completed 151 8 In Review 0 9 Unit Testing 0 11 Rework 0 12 Reopen 0 Now i need to add a where clause in this query, to retrive the data based on the user id in

GroupBy week/month

做~自己de王妃 提交于 2020-01-06 08:22:11
问题 I'm getting list of products from a database, each of them have populated paymentDate and I would like to format my data like this (just an example): { Week:1, Month:8, Total:50 }, { Week:2, Month:8, Total:40 }, { Week:3, Month:8, Total:70 }, { Week:4, Month:8, Total:85 } ... and so on.. Now I'm getting my data grouped by month and for 4 months it returns 4 INSTEAD OF 16 rows like: Month:8, Total:250 And that's what I don't want.. Here's my code: First I'm getting all rows from a last 4

Query objects for one to many relationship in LINQ

自作多情 提交于 2020-01-06 07:54:35
问题 I have a problem which seems to be quite similar to Query objects for one to many relationship in LINQ I've been trying to solve my problem referring the above but somehow I've been failing for a long time. The scenario I have a model named Business which has a ICollection of Branches and also the business belongs to a particular SubCategory . The model Looks something like public class SubCategory { public string Id { get; set; } public string Name { get; set; } public string Description {

Query objects for one to many relationship in LINQ

Deadly 提交于 2020-01-06 07:54:11
问题 I have a problem which seems to be quite similar to Query objects for one to many relationship in LINQ I've been trying to solve my problem referring the above but somehow I've been failing for a long time. The scenario I have a model named Business which has a ICollection of Branches and also the business belongs to a particular SubCategory . The model Looks something like public class SubCategory { public string Id { get; set; } public string Name { get; set; } public string Description {

How to get maximum Id in List and then return list

好久不见. 提交于 2020-01-06 07:44:35
问题 I have a structure like this: No ID Name Status 1 1 A 1 2 1 B 1 3 1 c 1 4 1 D 1 5 2 E 3 6 2 F 3 7 2 G 3 I want to run a linq when I get a list results get maximum row where for each status and row details as well.Like: No ID Name Status 4 1 D 1 7 2 G 3 Means latest entry for the status. Is there a way around, as I have tried all Max, Orderby descending but I get single result but I need a List as a result. 回答1: You have to extract the groups of a same id (GroupBy), and then export the max No

Find occurrence of a 'string' in a subgroup column and mark maingroup based on its occurrence

☆樱花仙子☆ 提交于 2020-01-06 07:10:45
问题 I have data which looks like this: Group string A Hello A SearchListing A GoSearch A pen A Hello B Real-Estate B Access B Denied B Group B Group C Glance C NoSearch C Home and so on I want to find out all those group who have "search" phrase in the strings and mark them as 0/1. At the same time I want to aggregate results like unique strings and total strings with respect to each group and also, how many times "search" was encountered by that group. The end results which I want is something

MySQL - Return number of rows matching query data?

淺唱寂寞╮ 提交于 2020-01-06 06:53:18
问题 I have a query as follows: SELECT 1 FROM shop_inventory a JOIN shop_items b ON b.id=a.iid AND b.szbid=3362169 AND b.cid=a.cid WHERE a.cid=1 GROUP BY a.bought The only thing I need to do with this data is work out the number of rows returned (which I could do with mysqli -> num_rows; . However, I would like to know if there is a method to return the number of rows that match the query, without having to run num_rows ? For example, the query should return one row, with one result, number_of

C# How to GroupBy so that an item can be put into multiple groups

孤人 提交于 2020-01-06 06:51:09
问题 I have a bunch of articles and I want to organize them by category. This would be simple with a GroupBy(x => x.Category), except that some articles have multiple categories. How can I group my articles so that if they have two categories, they are put into both category groupings? example: Article 1, category:apples, oranges Article 2, category:apples Article 3, cateogry:oranges I would end up with two categories, apples and oranges: apples: Article 1, Article 2 orange: Article 1, Article 3

How to do window function inside a when?

此生再无相见时 提交于 2020-01-06 06:03:33
问题 I have a dataframe where I am trying to do window function on a array column. The logic is as follows: Group by (or window partition) the id and filtered columns. Calculate the max score of the rows where the types column is null, otherwise take the score of that row. When score is not equal to the max score of the group add "NA" to the column type. val data = spark.createDataFrame(Seq( (1, "shirt for women", Seq("shirt", "women"), 19.1, "ST"), (1, "shirt for women", Seq("shirt", "women"), 10