aggregation

MYSQL count of count?

烈酒焚心 提交于 2019-11-28 11:36:05
I have a mysql table like: id, visitorid, pageid When a visitor hits the website it stores their visitor id and the page id as a row. I am trying to extract the number of visitors who hit the website exactly X times. (for a chart). so how many visit just one page, how many visit 2 pages... so far I have: SELECT COUNT(visid),visid FROM vislog GROUP BY visid ORDER BY COUNT(visid) DESC But I don't know how to do the next part of counting the counts. Is it possible to do as a mysql query? Edit: I have added my answer . You can wrap your query inside another one: SELECT cnt AS page_visits , COUNT(*

how to return the count of unique documents by using elasticsearch aggregation

岁酱吖の 提交于 2019-11-28 10:58:46
I encountered a problem that elasticsearch could not return the count of unique documents by just using terms aggregation on a nested field. Here is an example of our model: { ..., "location" : [ {"city" : "new york", "state" : "ny"}, {"city" : "woodbury", "state" : "ny"}, ... ], ... } I want to do aggregation on the state field, but this document will be counted twice in the 'ny' bucket since 'ny' appears twice in the document. So I'm wondering if where is a way to grab the count of distinct documents. mapping: people = { :properties => { :location => { :type => 'nested', :properties => {

R Dynamically build “list” in data.table (or ddply)

回眸只為那壹抹淺笑 提交于 2019-11-28 09:59:26
My aggregation needs vary among columns / data.frames. I would like to pass the "list" argument to the data.table dynamically. As a minimal example: require(data.table) type <- c(rep("hello", 3), rep("bye", 3), rep("ok",3)) a <- (rep(1:3, 3)) b <- runif(9) c <- runif(9) df <- data.frame(cbind(type, a, b, c), stringsAsFactors=F) DT <-data.table(df) This call: DT[, list(suma = sum(as.numeric(a)), meanb = mean(as.numeric(b)), minc = min(as.numeric(c))), by= type] will have result similar to this: type suma meanb minc 1: hello 6 0.1332210 0.4265579 2: bye 6 0.5680839 0.2993667 3: ok 6 0.5694532 0

Concatenating a column by a group in R

拟墨画扇 提交于 2019-11-28 09:50:41
问题 Suppose I've got this employee list: Dept Date Name ----- --------- --------------- 30 07-DEC-02 Raphaely 30 18-MAY-03 Khoo 40 07-JUN-02 Mavris 50 01-MAY-03 Kaufling 50 14-JUL-03 Ladwig 70 07-JUN-02 Baer 90 13-JAN-01 De Haan 90 17-JUN-03 King 100 16-AUG-02 Faviet 100 17-AUG-02 Greenberg 110 07-JUN-02 Gietz 110 07-JUN-02 Higgins I want a list aggregation by department in R (similar to Oracle PL/SQL's LISTAGG function) that would product this last column: Dept Date Name Emp_list ----- ---------

Single Responsibility Principle in Clean Architecture, Aggregating UseCases in one UseCaseManager which can provide UseCase based on In & Out Object.

╄→尐↘猪︶ㄣ 提交于 2019-11-28 08:49:22
问题 I want to implement Single Responsibility principle in my projects Domain layer (Clean MVVM). I've approx. 200 different use-cases which are being very hectic to manage. Now I'm thinking to create one UseCaseManager which can provide me required UseCase based on Input & Output Object. I've tried an approach but that's not looking very good.I'm mentioning some sample code, Please help me how can I aggregate all the UseCases to one UseCaseManager. UseCase1: public class ActualUseCase1 extends

When object A instantiates/aggrgate/acquaint object B, must object A have a field member referencing object B?

大城市里の小女人 提交于 2019-11-28 07:04:32
问题 From Design Pattern by GoF: An object reference representing a part-of or aggregation relationship is indicated by an arrowheaded line with a diamond at the base. The arrow points to the class that is aggregated (e.g., Shape). An arrowheaded line without the diamond denotes acquaintance (e.g., a LineShape keeps a reference to a Color object, which other shapes may share). A name for the reference may appear near the base to distinguish it from other references Another useful thing to show is

Count Number of Consecutive Occurrence of values in Table

可紊 提交于 2019-11-28 06:58:41
I have below table create table #t (Id int, Name char) insert into #t values (1, 'A'), (2, 'A'), (3, 'B'), (4, 'B'), (5, 'B'), (6, 'B'), (7, 'C'), (8, 'B'), (9, 'B') I want to count consecutive values in name column +------+------------+ | Name | Repetition | +------+------------+ | A | 2 | | B | 4 | | C | 1 | | B | 2 | +------+------------+ The best thing I tried is: select Name , COUNT(*) over (partition by Name order by Id) AS Repetition from #t order by Id but it doesn't give me expected result One approach is the difference of row numbers: select name, count(*) from (select t.*, (row

<unresolved overloaded function type> when trying to pass an aggregated object's method to its class method

こ雲淡風輕ζ 提交于 2019-11-28 05:43:03
问题 I have some problem compiling my code. I have the following structure: #include <cstdlib> using namespace std; typedef double (*FuncType)(int ); class AnotherClass { public: AnotherClass() {}; double funcAnother(int i) {return i*1.0;} }; class MyClass { public: MyClass(AnotherClass & obj) { obj_ = &obj;}; void compute(FuncType foo); void run(); protected: AnotherClass * obj_; /*pointer to obj. of another class */ }; void MyClass::compute(FuncType foo) { int a=1; double b; b= foo(a); } void

SQL Server pick random (or first) value with aggregation

谁说胖子不能爱 提交于 2019-11-28 05:24:12
问题 How can I get SQL Server to return the first value (any one, I don't care, it just needs to be fast) it comes across when aggregating? For example, let's say I have: ID Group 1 A 2 A 3 A 4 B 5 B and I need to get any one of the ID's for each group. I can do this as follows: Select max(id) ,group from Table group by group which returns ID Group 3 A 5 B That does the job, but it seems stupid to me to ask SQL Server to calculate the highest ID when all it really needs to do is to pick the first

How can I vectorize the averaging of 2x2 sub-arrays of numpy array?

强颜欢笑 提交于 2019-11-28 04:23:09
问题 I have a very a very large 2D numpy array that contains 2x2 subsets that I need to take the average of. I am looking for a way to vectorize this operation. For example, given x: # |- col 0 -| |- col 1 -| |- col 2 -| x = np.array( [[ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0], # row 0 [ 6.0, 7.0, 8.0, 9.0, 10.0, 11.0], # row 0 [12.0, 13.0, 14.0, 15.0, 16.0, 17.0], # row 1 [18.0, 19.0, 20.0, 21.0, 22.0, 23.0]]) # row 1 I need to end up with a 2x3 array which are the averages of each 2x2 sub array, i.e.: