group-by

How should I modify this SQL statement?

走远了吗. 提交于 2020-01-14 13:29:19
问题 My SQL Server view SELECT geo.HyperLinks.CatID, geo.Tags.Tag, geo.HyperLinks.HyperLinksID FROM geo.HyperLinks LEFT OUTER JOIN geo.Tags INNER JOIN geo.TagsList ON geo.Tags.TagID = geo.TagsList.TagID ON geo.HyperLinks.HyperLinksID = geo.TagsList.HyperLinksID WHERE HyperLinksID = 1 returns these... HyperLinksID CatID Tags 1 2 Sport 1 2 Tennis 1 2 Golf How should I modify the above to have results like HyperLinksID CatID TagsInOneRowSeperatedWithSpaceCharacter 1 2 Sport Tennis Golf UPDATE: As

Weird behaviour with groupby on ordered categorical columns

倖福魔咒の 提交于 2020-01-14 07:04:16
问题 MCVE df = pd.DataFrame({ 'Cat': ['SF', 'W', 'F', 'R64', 'SF', 'F'], 'ID': [1, 1, 1, 2, 2, 2] }) df.Cat = pd.Categorical( df.Cat, categories=['R64', 'SF', 'F', 'W'], ordered=True) As you can see, I've define an ordered categorical column on Cat . To verify, check; 0 SF 1 W 2 F 3 R64 4 SF 5 F Name: Cat, dtype: category Categories (4, object): [R64 < SF < F < W] I want to find the largest category PER ID. Doing groupby + max works. df.groupby('ID').Cat.max() ID 1 W 2 F Name: Cat, dtype: object

Group rows based on column sum value

安稳与你 提交于 2020-01-14 06:50:46
问题 I have a table with 3 columns as shown below: id | num_rows id | num_rows | group_id -----|--------- -----|----------|-------- 2502 | 330 2502 | 330 | 9 3972 | 150 3972 | 150 | 9 3988 | 200 =============> 3988 | 200 | 8 4228 | 280 Desired output 4228 | 280 | 8 3971 | 510 =============> 3971 | 510 | 1 52 | 1990 52 | 1990 | 2 895 | 2000 895 | 2000 | 3 812 | 5596 812 | 5596 | 4 1600 | 7462 1600 | 7462 | 5 910 | 7526 910 | 7526 | 6 638 | 11569 638 | 11569 | 7 id is a unique identifier for

Group rows based on column sum value

和自甴很熟 提交于 2020-01-14 06:50:25
问题 I have a table with 3 columns as shown below: id | num_rows id | num_rows | group_id -----|--------- -----|----------|-------- 2502 | 330 2502 | 330 | 9 3972 | 150 3972 | 150 | 9 3988 | 200 =============> 3988 | 200 | 8 4228 | 280 Desired output 4228 | 280 | 8 3971 | 510 =============> 3971 | 510 | 1 52 | 1990 52 | 1990 | 2 895 | 2000 895 | 2000 | 3 812 | 5596 812 | 5596 | 4 1600 | 7462 1600 | 7462 | 5 910 | 7526 910 | 7526 | 6 638 | 11569 638 | 11569 | 7 id is a unique identifier for

Using linq to group a table that contains substrings

谁都会走 提交于 2020-01-14 05:40:15
问题 My Data Table(DeviceInfo): ID | OS | Device ----------------------------------------------- 1 | Android 2.2 | Samsung 2 | Linux/Android 4.2 | LG 3 | Linux/Android 4.4.2 | HTC 4 | Android 3.2 | Samsung 5 | Android 3.0 | Motorola 6 | iOS 7.1.2 | iPad 7 | iOS 8.0 | iPhone 6 8 | iOS 6.1.6 | iPhone 4 I want to group this table by Android and ios user using Linq.Actually I have to group the table using the substring "Android" and "iOS". My Output should be ID | User | Count ------------------------

php mysql group by date with yyyy-mm-dd format

末鹿安然 提交于 2020-01-14 03:23:05
问题 I had a mysql table called events with the fields: id, date, and name. The date field has the format yyyy-mm-dd hh::mm:ss edit: meaning it is in datetime format I want to group the events by day, and I wasn't sure how to approach this- is there a way to select only the month and day from the field? or should i use PHP after I select all the "events" my end goal is to have something like this: March 10th: event1, event2 March 11th: event4, event5 I found MySQL select using datetime, group by

LINQ Group By to project into a non-anonymous type?

纵饮孤独 提交于 2020-01-13 19:08:35
问题 I have the following LINQ example: var colorDistribution = from product in ctx.Products group product by product.Color into productColors select new { Color = productColors.Key, Count = productColors.Count() }; All this works and makes perfect sense. What I'm trying to achieve is to group by into a strong type instead of anonymous type. For example I have a ProductColour class and I would like to Group into a List<ProductColour> Is this possible? Thank you 回答1: EDIT: Okay, I'd completely

LINQ Group By to project into a non-anonymous type?

痞子三分冷 提交于 2020-01-13 19:08:28
问题 I have the following LINQ example: var colorDistribution = from product in ctx.Products group product by product.Color into productColors select new { Color = productColors.Key, Count = productColors.Count() }; All this works and makes perfect sense. What I'm trying to achieve is to group by into a strong type instead of anonymous type. For example I have a ProductColour class and I would like to Group into a List<ProductColour> Is this possible? Thank you 回答1: EDIT: Okay, I'd completely

LINQ GroupBy Anonymous Type

走远了吗. 提交于 2020-01-13 11:43:10
问题 I am wondering why GroupBy works with anonymous types. List<string> values = new List<string>(); values.GroupBy(s => new { Length = s.Length, Value = s }) Anonymous types do not implement any interfaces, so I am confused how this is working. I assume that the algorithm is working by creating an instance of the anonymous type for each item in the source and using hashing to group the items together. However, no IEqualityComparer is provided to define how to generate a hash or whether two

pandas dataframe groupby and join

最后都变了- 提交于 2020-01-13 09:48:10
问题 Let's suppose to have this: np.random.seed(123) df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], 'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], 'C' : np.random.randn(8), 'D' : np.random.randn(8)}) So the dataframe appears like below: A B C D 0 foo one -1.085631 1.265936 1 bar one 0.997345 -0.866740 2 foo two 0.282978 -0.678886 3 bar three -1.506295 -0.094709 4 foo two -0.578600 1.491390 5 bar two 1.651437 -0.638902 6 foo one -2.426679 -0