aggregate

Get max average for each distinct record in a SQL Query

梦想与她 提交于 2019-12-23 09:32:39
问题 I have some tables that contain data about players and the games they have bowled this season in a bowling center during their leagues. What this particular query is used for is to sort the top X averages this year for men and for women. I have all of this down, but I still have a problem in some particular case when some players play in multiple leagues and have more than one of their averages in the top X. Obviously, I only want to list the best average for a given player, so if Player A

Spring data mongodb application design and data aggregation

老子叫甜甜 提交于 2019-12-23 05:25:11
问题 I was developing a little application with spring data mongo and angularjs . Here is model : public class Lease { @Id private String id; private long created; private Lessor lessor; private Lessee lessee; } public class Payment { @Id private String id; private Integer month; private Integer year; private Long amount; private String leaseId; } I did not embed Payment model as I need it to have an id and edit it in its own form. On the main page of the app it represents a list of leases with

Spring data mongodb application design and data aggregation

…衆ロ難τιáo~ 提交于 2019-12-23 05:25:07
问题 I was developing a little application with spring data mongo and angularjs . Here is model : public class Lease { @Id private String id; private long created; private Lessor lessor; private Lessee lessee; } public class Payment { @Id private String id; private Integer month; private Integer year; private Long amount; private String leaseId; } I did not embed Payment model as I need it to have an id and edit it in its own form. On the main page of the app it represents a list of leases with

Ruby Rails Complex SQL with aggregate function and DayOfWeek

◇◆丶佛笑我妖孽 提交于 2019-12-23 02:57:07
问题 Rails 2.3.4 I have searched google, and have not found an answer to my dilemma. For this discussion, I have two models. Users and Entries. Users can have many Entries (one for each day). Entries have values and sent_at dates. I want to query and display the average value of entries for a user BY DAY OF WEEK. So if a user has entered values for, say, the past 3 weeks, I want to show the average value for Sundays, Mondays, etc. In MySQL, it is simple: SELECT DAYOFWEEK(sent_at) as day, AVG(value

Pandas: Get top 10 values AFTER grouping

流过昼夜 提交于 2019-12-23 02:36:53
问题 I have a pandas data frame with a column 'id' and a column 'value'. It is already sorted by first id (ascending) and then value (descending). What I need is the top 10 values per id. I assumed that something like the following would work, but it doesn't: df.groupby("id", as_index=False).aggregate(lambda (index,rows) : rows.iloc[:10]) What I get is just a list of ids, the value column (and other columns that I omitted for the question) aren't there anymore. Any ideas how it might be done,

Aggregating in SQL

做~自己de王妃 提交于 2019-12-22 18:42:57
问题 I have a table that looks like this: Conversion_Date User_Name Last_Date_Touch Touch_Count 7/15/2017 A 6/17/2017 1 7/16/2017 B 6/24/2017 2 7/19/2017 A 6/20/2017 1 7/19/2017 C 6/29/2017 1 I want to get the sum of Touch_Count from the last 30 days for each Conversion_Date by User_Name in SQL. The only thing I could think of at first was to figure out the time window for each conversion date going back 30 days and then I'm not sure how to aggregate this to get the final result. First it was

MongoDB aggregate queries vs. MySQL SELECT field1 FROM table

╄→尐↘猪︶ㄣ 提交于 2019-12-22 17:29:35
问题 I am completely new to MongoDB and wanted to compare query performance of a NoSQL data model relative to its relational database counter part. I wrote this into MongoDB shell // Make 10 businesses // Each business has 10 locations // Each location has 10 departments // Each department has 10 teams // Each team has 100 employees (new Array(10)).fill(0).forEach(_=> db.businesses.insert({ "name":"Business Name", "locations":(new Array(10)).fill(0).map(_=>({ "name":"Office Location", "departments

Applying multiple functions to each column in a data frame using aggregate

筅森魡賤 提交于 2019-12-22 10:34:00
问题 When I need to apply multiple functions to multiple columns sequentially and aggregate by multiple columns and want the results to be bound into a data frame I usually use aggregate() in the following manner: # bogus functions foo1 <- function(x){mean(x)*var(x)} foo2 <- function(x){mean(x)/var(x)} # for illustration purposes only npk$block <- as.numeric(npk$block) subdf <- aggregate(npk[,c("yield", "block")], by = list(N = npk$N, P = npk$P), FUN = function(x){c(col1 = foo1(x), col2 = foo2(x))

Aggregate time column on hourly interval in R

元气小坏坏 提交于 2019-12-22 10:18:48
问题 I have a df in R in the following format. What could be the easiest way to aggregate this on an hourly time interval basis, currently it is every minute theTime24 Amount 988 2015-02-04 23:53:00 2 989 2015-02-04 23:55:00 1 990 2015-02-04 23:56:00 3 991 2015-02-04 23:57:00 2 992 2015-02-04 23:58:00 1 993 2015-02-04 23:59:00 2 回答1: (Since the user (@user20650) who answered added it as a comment, I am answering my own question) aggregate(Amount ~ format(as.POSIXct(countByCountryTime$theTime24), "

Pandas fails to aggregate with a list of aggregation functions

流过昼夜 提交于 2019-12-22 09:40:11
问题 How do I specify custom aggregating functions so that they behave correctly when used in list arguments of pandas.DataFrame.aggregate ? Given a two-column dataframe in pandas ... import pandas as pd import numpy as np df = pd.DataFrame(index=range(10)) df['a'] = [ 3 * x for x in range(10) ] df['b'] = [ 1 -2 * x for x in range(10) ] ... aggregating over a list of aggregation function specs is not a problem: def ok_mean(x): return x.mean() df.aggregate(['mean', np.max, ok_mean]) a b mean 13.5