group-by

Elasticsearch terms aggregation and querying

▼魔方 西西 提交于 2020-01-06 02:22:36
问题 I have two types of log messages: Jul 23 09:24:16 rrr mrr-core[222]: Aweg3AOMTs_1563866656871111.mt processMTMessage() #12798 realtime: 5.684 ms Jul 23 09:24:18 rrr mrr-core[2222]: Aweg3AOMTs_1563866656871111.0.dn processDN() #7750 realtime: 1.382 ms The first message is kind of sent message and second is message which confirm that message was delivered. The difference between them is the suffix which I have separated from "id" and can query it. These messages are parsed and stored in

Select for Opened, Closed and Backlog

三世轮回 提交于 2020-01-06 01:56:05
问题 I have the following table: +-------------+---------------------+---------------------+ | status | open_time | close_time | +-------------+---------------------+---------------------+ | closed | 01-11-2014 19:32:44 | 01-11-2014 20:32:44 | | open | 01-12-2014 22:33:49 | 02-12-2014 22:33:49 | | open | 01-23-2014 22:08:24 | 03-23-2014 22:08:24 | | closed | 02-01-2014 22:33:57 | 03-01-2014 22:33:57 | | open | 02-01-2013 22:37:34 | 02-01-2013 23:37:34 | | closed | 04-20-2013 15:23:00 | 05-20-2013

Does RAILS have GROUP BY…WITH ROLLUP query?

[亡魂溺海] 提交于 2020-01-05 11:03:40
问题 GROUP BY... WITH ROLLUP is a cool feature in sql. Does Rails support ROLLUP ? How can I write the query like, .group('column1, column2,....') 回答1: I normally use it like @rollup = People.select(:occupation, :state, 'COUNT(`state`) as cnt') .group(:occupation, 'state WITH ROLLUP') .to_a.map(&:attributes) then in my view use @rollup.first["state"] etc. 回答2: You can use the RollUp clause in the group method of ruby . Let take an example, we have sql query like SELECT * FROM Lead GROUP BY ROLLUP

detecting sequence by group and compute new variable for the subset

我们两清 提交于 2020-01-05 10:32:35
问题 I need to detect a sequence by group in a data.frame and compute new variable. Consider I have this following data.frame : df1 <- data.frame(ID = c(1,1,1,1,1,1,1,2,2,2,3,3,3,3), seqs = c(1,2,3,4,5,6,7,1,2,3,1,2,3,4), count = c(2,1,3,1,1,2,3,1,2,1,3,1,4,1), product = c("A", "B", "C", "C", "A,B", "A,B,C", "D", "A", "B", "A", "A", "A,B,C", "D", "D"), stock = c("A", "A,B", "A,B,C", "A,B,C", "A,B,C", "A,B,C", "A,B,C,D", "A", "A,B", "A,B", "A", "A,B,C", "A,B,C,D", "A,B,C,D")) df1 > df1 ID seqs

LINQ group-by and then display datetime for (dd mmm)

﹥>﹥吖頭↗ 提交于 2020-01-05 10:16:05
问题 I want Linq to group by date but display in text here is my code var groups = _uow.Orders.GetAll() .Where(x => x.Created > baselineDate) .GroupBy(x => x.Created.ToString("yyyy-MM-dd")); var orders = new { Day = groups.Select(g => g.Key).ToArray(), Total = groups.Select(g => g.Sum(t => t.Total)).ToArray(), }; the result is (not good to put in label of graph) {"Day": [2, 3, 4, 5], "Total": [9999.00, 9999.00, 9999.00, 9999.00] } But i want this (Monthly) "Day": ['Jan', Feb', 'Mar', 'Apr'],

HAVING - GROUP BY to get the latest record

我怕爱的太早我们不能终老 提交于 2020-01-05 10:11:48
问题 I have a table called RESULTS like this : RESULTS_IDN NAME SUBJECT YEAR QUALIFIED 1 MARK ENGLISH 1989 N 3 MARK ENGLISH 1991 N 5 MARK ENGLISH 1993 Y 7 MARK ENGLISH 1995 N 2 MARK MATH 1990 N 5 MARK MATH 1993 N 6 MARK MATH 1995 Y 4 MARK SCIENCE 1991 N 9 MARK SCIENCE 1997 Y I need to know the Qualification Status of the CANDIDATE for a SUBJECT for the LATEST exam he has written , how do I write a query for this (ORACLE/MSSQL) ? For example Input NAME,SUBJECT OUTPUT NAME IDN SUBJECT YEAR Q MARK

Can't Remove Duplicate Rows

对着背影说爱祢 提交于 2020-01-05 09:15:19
问题 Each record could have up to 40 different person_user.description fields. Problem is, I am getting duplicate rows because records have multiple description entries. Can you help me put those additional duplicates on the same record row like: |1|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| |2|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| |3|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| instead of this: |1

Can't Remove Duplicate Rows

假装没事ソ 提交于 2020-01-05 09:15:12
问题 Each record could have up to 40 different person_user.description fields. Problem is, I am getting duplicate rows because records have multiple description entries. Can you help me put those additional duplicates on the same record row like: |1|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| |2|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| |3|badge.bid|person.first_name|person.last_name|person.type|1|2|3|4|5|etc|40| instead of this: |1

Conditional grouping clause (sqlite)

冷暖自知 提交于 2020-01-05 08:52:15
问题 Inside a SELECT statement, is it possible to GROUP BY col_A if col_B = "some_value" , otherwise GROUP BY col_C ? Then have that field that was used for grouping inside the results? Like SELECT value_of_the_column_used_for_group FROM table WHERE ... GROUP BY (IF col_B = "some_value" : col_A : ELSE : col_C) LIMIT 0, 20; Basically I want to select children records that have distinct parents or parent records that have distinct IDs. But I want to select parent IDs, which can be the ID column or

Conditional grouping clause (sqlite)

巧了我就是萌 提交于 2020-01-05 08:52:14
问题 Inside a SELECT statement, is it possible to GROUP BY col_A if col_B = "some_value" , otherwise GROUP BY col_C ? Then have that field that was used for grouping inside the results? Like SELECT value_of_the_column_used_for_group FROM table WHERE ... GROUP BY (IF col_B = "some_value" : col_A : ELSE : col_C) LIMIT 0, 20; Basically I want to select children records that have distinct parents or parent records that have distinct IDs. But I want to select parent IDs, which can be the ID column or