aggregate-functions

Distinct LISTAGG that is inside a subquery in the SELECT list

三世轮回 提交于 2019-11-27 06:59:25
问题 Here is a minimal working example of what I'm trying to do and what I'm getting: I have a query as follows: /* with tran_party as -- ALL DUMMY DATA ARE IN THESE CTE FOR YOUR REFERENCE (select 1 tran_party_id, 11 transaction_id, 101 team_id_redirect from dual union all select 2, 11, 101 from dual union all select 3, 11, 102 from dual union all select 4, 12, 103 from dual union all select 5, 12, 103 from dual union all select 6, 12, 104 from dual union all select 7, 13, 104 from dual union all

LINQ aggregate and group by periods of time

半腔热情 提交于 2019-11-27 06:53:49
I'm trying to understand how LINQ can be used to group data by intervals of time; and then ideally aggregate each group. Finding numerous examples with explicit date ranges, I'm trying to group by periods such as 5-minutes, 1-hour, 1-day. For example, I have a class that wraps a DateTime with a value: public class Sample { public DateTime timestamp; public double value; } These observations are contained as a series in a List collection: List<Sample> series; So, to group by hourly periods of time and aggregate value by average, I'm trying to do something like: var grouped = from s in series

R Dataframe: aggregating strings within column, across rows, by group

蹲街弑〆低调 提交于 2019-11-27 06:24:17
问题 I have what seems like a very inefficient solution to a peculiar problem. I have text data which, for various reasons, is broken across rows of a dataframe at random intervals. However, certain subsets of are known to belong together based on unique combinations of other variables in the dataframe. See, for example, a MWE demonstrating the structure and my initial solution: # Data df <- read.table(text="page passage person index text 1 123 A 1 hello 1 123 A 2 my 1 123 A 3 name 1 123 A 4 is 1

Sql aggregate function to obtain a list

冷暖自知 提交于 2019-11-27 06:09:46
问题 Hei! How can I create an aggregate function to obtain a list of the aggregate values. given : key value Andrei 1 Andrei 2 Andrei 3 Mihai 4 Mihai 5 Mihai 6 I want key list Andrei 1,2,3 Mihai 4,5,6 回答1: I used this article once to to the exact same thing: http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/ 回答2: MS SQL solution: [Note: This solution only works on SQL 2005 and later. Original question didn't specify the version in use.] SELECT key , STUFF(

MYSQL CONCAT MAX LENGTH

两盒软妹~` 提交于 2019-11-27 05:57:30
问题 Following this post: POST ABOUT CONCAT My problem is that i have many rows CONCAT into one row. For example if i have 10 rows with string around 50 chars, my query will show me only 6-7 of that rows or something like that. I searech in stack and google and i found that i can change CONCAT max length by command: SET group_concat_max_len := @@max_allowed_packet . What i am doing wrong? EDIT: When i SHOW VARIABLES LIKE 'group_concat_max_len' it's shows me 1024. Mysql version 5.0.96-log. Tables

Using GROUP BY with FIRST_VALUE and LAST_VALUE

北城以北 提交于 2019-11-27 05:51:49
问题 I'm working with some data that is currently stored in 1 minute intervals that looks like this: CREATE TABLE #MinuteData ( [Id] INT , [MinuteBar] DATETIME , [Open] NUMERIC(12, 6) , [High] NUMERIC(12, 6) , [Low] NUMERIC(12, 6) , [Close] NUMERIC(12, 6) ); INSERT INTO #MinuteData ( [Id], [MinuteBar], [Open], [High], [Low], [Close] ) VALUES ( 1, '2015-01-01 17:00:00', 1.557870, 1.557880, 1.557870, 1.557880 ), ( 2, '2015-01-01 17:01:00', 1.557900, 1.557900, 1.557880, 1.557880 ), ( 3, '2015-01-01

Why is PostgreSQL array access so much faster in C than in PL/pgSQL?

旧城冷巷雨未停 提交于 2019-11-27 05:25:34
问题 I have a table schema which includes an int array column, and a custom aggregate function which sums the array contents. In other words, given the following: CREATE TABLE foo (stuff INT[]); INSERT INTO foo VALUES ({ 1, 2, 3 }); INSERT INTO foo VALUES ({ 4, 5, 6 }); I need a "sum" function that would return { 5, 7, 9 } . The PL/pgSQL version, which works correctly, is as follows: CREATE OR REPLACE FUNCTION array_add(array1 int[], array2 int[]) RETURNS int[] AS $$ DECLARE result int[] := ARRAY[

Group by data intervals

让人想犯罪 __ 提交于 2019-11-27 04:35:10
问题 I have a single table which stores bandwidth usage on the network over a period of time. One column will contain the date time (primary key) and another column will record the bandwidth. Data is recorded every minute. We will have other columns recording other data at that moment in time. If the user requests the data on 15 minute intervals (within a 24 hour period given start and end date), is it possible with a single query to get the data I require or would I have to write a stored

use mysql SUM() in a WHERE clause

天大地大妈咪最大 提交于 2019-11-27 04:29:29
问题 suppose I have this table id | cash 1 200 2 301 3 101 4 700 and I want to return the first row in which the sum of all the previous cash is greater than a certain value: So for instance, if I want to return the first row in which the sum of all the previous cash is greater than 500, is should return to row 3 How do I do this using mysql statement? using WHERE SUM(cash) > 500 doesn't work 回答1: You can only use aggregates for comparison in the HAVING clause: GROUP BY ... HAVING SUM(cash) > 500

mysql count group by having

房东的猫 提交于 2019-11-27 04:21:43
问题 I have this table: Movies (ID, Genre) A movie can have multiple genres, so an ID is not specific to a genre, it is a many to many relationship. I want a query to find the total number of movies which have at exactly 4 genres. The current query I have is SELECT COUNT(*) FROM Movies GROUP BY ID HAVING COUNT(Genre) = 4 However, this returns me a list of 4's instead of the total sum. How do I get the sum total sum instead of a list of count(*) ? 回答1: One way would be to use a nested query: SELECT