aggregate

SQL CE DISTINCT AGGREGATE

旧城冷巷雨未停 提交于 2020-01-11 12:04:13
问题 Does SQL CE has the ability to use distinct in aggregate functions? I need something like SELECT count(distinct date) FROM table This is simplified query and I already have GROUP BY used in original one. 回答1: SQL Server CE (current version) does not support count(distinct) The workaround is a GROUP BY, which sounds like what you are using select count(*) from ( select distinct date from tbl ) x Or if other fields are involved select groupcol, count(*) from ( select groupcol, date from tbl

Pandas Group by sum of all the values of the group and another column as comma separated

点点圈 提交于 2020-01-11 12:02:27
问题 I want to group by one column (tag) and sum up the corresponding quantites (qty). The related reference no. column should be separated by commas import pandas as pd tag = ['PO_001045M100960','PO_001045M100960','PO_001045MSP2526','PO_001045M870191', 'PO_001045M870191', 'PO_001045M870191'] reference= ['PA_000003', 'PA_000005', 'PA_000001', 'PA_000002', 'PA_000004', 'PA_000009'] qty=[4,2,2,1,1,1] df = pd.DataFrame({'tag' : tag, 'reference':reference, 'qty':qty}) tag reference qty PO

Parse CSV file with and aggregate values, multiple columns

≡放荡痞女 提交于 2020-01-11 10:53:10
问题 I would like to adapt the post here (Parse CSV file and aggregate the values) to sum multiple columns instead of just one. So for these data: CITY,AMOUNT,AMOUNT2,AMOUNTn London,20,21,22 Tokyo,45,46,47 London,55,56,57 New York,25,26,27 How can I get this: CITY,AMOUNT,AMOUNT2,AMOUNTn London,75,77,79 Tokyo,45,46,47 New York,25,26,27 I will have several thousand columns eventually, and unfortunately I can not use the pandas package for this task. Here is the code I have just aggregates all three

Aggregate linear regression

主宰稳场 提交于 2020-01-11 09:36:30
问题 Sorry I am quite new to R, but I have a dataframe with gamelogs for multiple players. I am trying to get the slope coefficient for each player's points over all of their games. I have seen that aggregate can use operators like sum and average , and getting coefficients off of a linear regression is pretty simple as well . How do I combine these? a <- c("player1","player1","player1","player2","player2","player2") b <- c(1,2,3,4,5,6) c <- c(15,12,13,4,15,9) gamelogs <- data.frame(name=a, game=b

如何在spring-data-mongo aggregate指定多个字段为_id

半世苍凉 提交于 2020-01-10 17:39:06
mongo在做聚合group操作的时候,经常会遇到 联合字段唯一的场景。这里记录一下,在java中如何写group语句 Fields fields = Fields.fields(); Fields and = fields.and(Fields.field("$userOrder.advisory", "adv")).and(Fields.field("$innerState", "innerState")); Field adv = Fields.field("adv", "$_id.advisory"); Field innerState = Fields.field("innerState", "$_id.innerState"); Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation.group(and), Aggregation.project(Fields.from(adv, innerState))); 在使用 mongoOperations.aggregate() 执行聚合操作在接受聚合返回是,id无法直接映射为具体的对象。通过使用project来将id中的字段释放出来,这样就可以难道联合分组的keys了。 //执行聚合 返回类型为

Summary of data for each year in R

心已入冬 提交于 2020-01-10 11:35:10
问题 I have a data with two columns. In one column it is date and in another column it is flow data. I was able to read the data as date and flow data. I used the following code: creek <- read.csv("creek.csv") library(ggplot2) creek[1:10,] colnames(creek) <- c("date","flow") creek$date <- as.Date(creek$date, "%m/%d/%Y") The link to my data is https://www.dropbox.com/s/eqpena3nk82x67e/creek.csv Now, I want to find the summary of each year. I want to especially know mean, median, maximum etc. Thanks

Where can we use list initialization?

≯℡__Kan透↙ 提交于 2020-01-09 09:49:28
问题 This question already covers what PODs and aggregates are, and provides some examples on aggregate initialization. The question here is where can you use list initialization? Also where can you use (in lack of a better term) list assignment? An answer should deal with both C++03 and C++11, highlighting the differences between them. 回答1: C++03 List initialization In C++03 you can only use list-initialization for aggregates (C++03 [dcl.init.aggr]) and scalar (C++03 [dcl.init]/13) types: int i =

can I get count() and rows from one sql query in sql server?

非 Y 不嫁゛ 提交于 2020-01-09 05:29:06
问题 I'd like to get the total count of results and top n rows of some query - is it possible in one statement? I'd expect the results as: count(..) column1 column2 125 some_value some_value 125 some_value some_value Thank you in advance! 回答1: Like this: SELECT TOP 100 --optional MC.Cnt, M.Column1, M.Column2 FROM myTable M CROSS JOIN (SELECT COUNT(*) AS Cnt FROM myTable) MC Edit: After downvote and COUNT/OVER answer. A comparison on 2 tables of mine You can see a huge difference between my CROSS

Extract row corresponding to minimum value of a variable by group

♀尐吖头ヾ 提交于 2020-01-08 08:52:31
问题 I wish to (1) group data by one variable ( State ), (2) within each group find the row of minimum value of another variable ( Employees ), and (3) extract the entire row. (1) and (2) are easy one-liners, and I feel like (3) should be too, but I can't get it. Here is a sample data set: > data State Company Employees 1 AK A 82 2 AK B 104 3 AK C 37 4 AK D 24 5 RI E 19 6 RI F 118 7 RI G 88 8 RI H 42 data <- structure(list(State = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("AK", "RI")

Extract row corresponding to minimum value of a variable by group

这一生的挚爱 提交于 2020-01-08 08:51:14
问题 I wish to (1) group data by one variable ( State ), (2) within each group find the row of minimum value of another variable ( Employees ), and (3) extract the entire row. (1) and (2) are easy one-liners, and I feel like (3) should be too, but I can't get it. Here is a sample data set: > data State Company Employees 1 AK A 82 2 AK B 104 3 AK C 37 4 AK D 24 5 RI E 19 6 RI F 118 7 RI G 88 8 RI H 42 data <- structure(list(State = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("AK", "RI")