group-by

COUNT(DISTINCT) in multiple columns in SQL Server 2008

南楼画角 提交于 2020-01-24 05:54:59
问题 In Oracle, it's possible to get a count of distinct values in multiple columns by using the || operator (according to this forum post, anyway): SELECT COUNT(DISTINCT ColumnA || ColumnB) FROM MyTable Is there a way to do this in SQL Server 2008? I'm trying to perform a single query to return some group statistics, but I can't seem to do it. For example, here is a table of values I'm trying to query: AssetId MyId TheirId InStock 328 10 10 1 328 20 20 0 328 30 30 0 328 40 10 0 328 10 10 0 328 10

SQL Geography data type column in GROUP BY clause

寵の児 提交于 2020-01-24 05:49:39
问题 I'm using SQL Server and creating a script which will get the workers geographical location out of my database. The script is below. SELECT w.display_name, w.geo_location FROM jobs j WITH(NOLOCK) INNER JOIN workers w WITH(NOLOCK) ON w.worker_id = j.worker_id WHERE ..... The problem is that I want to add GROUP BY w.display_name, w.geo_location to the script as there are duplicate records being shown. Added a column with the data type geography to a group by clause causes an error to be thrown.

Group by aggregate in R

孤者浪人 提交于 2020-01-23 16:59:27
问题 I have a CSV file with the following data: ID Name Batch Marks Grade 1 A 2010 43 C 2 B 2011 88 A 3 C 2011 89 A 4 D 2010 47 C 5 E 2011 82 A Using R language, I need to take aggregate of the marks of students for the individual batches. What can I use as Rollup function is not available any more in R? I really dont know how to start. Please help. 回答1: aggregate is a good choice here. with(nameOfYourDataFrame, aggregate(X=Marks, by=list(Batch), FUN=sum)) aggregate takes three arguments: X : the

Group by aggregate in R

谁说胖子不能爱 提交于 2020-01-23 16:59:24
问题 I have a CSV file with the following data: ID Name Batch Marks Grade 1 A 2010 43 C 2 B 2011 88 A 3 C 2011 89 A 4 D 2010 47 C 5 E 2011 82 A Using R language, I need to take aggregate of the marks of students for the individual batches. What can I use as Rollup function is not available any more in R? I really dont know how to start. Please help. 回答1: aggregate is a good choice here. with(nameOfYourDataFrame, aggregate(X=Marks, by=list(Batch), FUN=sum)) aggregate takes three arguments: X : the

group by in LINQ query

我的梦境 提交于 2020-01-23 15:21:05
问题 I've got a DataTable where i want to perform a GroupBy query on. year url type id ============================= someurl image 0 2003 date 0 someurl image 1 2009 date 1 I've managed to group on my id, but I am not able to select the columns "year" and "Url". This is my query: var query = from row in table.AsEnumerable() let uri = row["uri"] group row by row.Field<int>("id") into grp orderby grp.Key select new { ID = grp.Key, }; How can i select the columns year and url? Thanks in advance. 回答1:

Aggregating string columns using pandas GroupBy

我的梦境 提交于 2020-01-23 11:08:38
问题 I have a DF such as the following: df = vid pos value sente 1 a A 21 2 b B 21 3 b A 21 3 a A 21 1 d B 22 1 a C 22 1 a D 22 2 b A 22 3 a A 22 Now I want to combine all rows with the same value for sente and vid into one row with the values for value joined by an " " df2 = vid pos value sente 1 a A 21 2 b B 21 3 b a A A 21 1 d a a B C D 22 2 b A 22 3 a A 22 I suppose a modification of this should do the trick: df2 = df.groupby["sente"].agg(lambda x: " ".join(x)) But I can't seem to figure out

Aggregating string columns using pandas GroupBy

十年热恋 提交于 2020-01-23 11:06:08
问题 I have a DF such as the following: df = vid pos value sente 1 a A 21 2 b B 21 3 b A 21 3 a A 21 1 d B 22 1 a C 22 1 a D 22 2 b A 22 3 a A 22 Now I want to combine all rows with the same value for sente and vid into one row with the values for value joined by an " " df2 = vid pos value sente 1 a A 21 2 b B 21 3 b a A A 21 1 d a a B C D 22 2 b A 22 3 a A 22 I suppose a modification of this should do the trick: df2 = df.groupby["sente"].agg(lambda x: " ".join(x)) But I can't seem to figure out

DAX expression for COUNT of GROUPBY

老子叫甜甜 提交于 2020-01-23 09:51:54
问题 I am new to PowerBI and writing DAX expressions. I have a table with a text column with different values.All I want to do is get the count for each distinct value. It's easily achieved with this SQL but I can't get the right DAX expression for it. select [value],count(*) as TagCount from Tags group by [value] order by TagCount desc Any help? 回答1: You can do something similar in Power BI as follows: SUMMARIZE(Tags, Tags[value], "TagCount", COUNT(Tags[value])) or SUMMARIZECOLUMNS(Tags[value],

DAX expression for COUNT of GROUPBY

半腔热情 提交于 2020-01-23 09:51:10
问题 I am new to PowerBI and writing DAX expressions. I have a table with a text column with different values.All I want to do is get the count for each distinct value. It's easily achieved with this SQL but I can't get the right DAX expression for it. select [value],count(*) as TagCount from Tags group by [value] order by TagCount desc Any help? 回答1: You can do something similar in Power BI as follows: SUMMARIZE(Tags, Tags[value], "TagCount", COUNT(Tags[value])) or SUMMARIZECOLUMNS(Tags[value],

Get minimum value between two columns for each row

时间秒杀一切 提交于 2020-01-23 07:42:34
问题 This is my data table: | uid | date | visit | transactionDate | +-----+----------+-------+-----------------+ | 1 | 6/2/2014 | 1 | 6/9/2014 | | 1 | 6/2/2014 | 1 | 8/4/2014 | | 2 | 6/2/2014 | 1 | 8/2/2014 | | 2 | 6/2/2014 | 1 | 10/17/2014 | | 2 | 6/2/2014 | 1 | 10/20/2014 | | 3 | 6/2/2014 | 1 | 6/9/2014 | | 3 | 6/2/2014 | 1 | 6/10/2014 | | 3 | 6/2/2014 | 1 | 6/11/2014 | | 3 | 6/2/2014 | 1 | 6/12/2014 | | 3 | 6/2/2014 | 1 | 6/14/2014 | | 3 | 6/2/2014 | 1 | 6/15/2014 | | 3 | 6/2/2014 | 1 | 6/17