aggregate-functions Questions

2

Solved

I have a large table, which I want to group by one column value and produce an aggregate of another column value. As an aggregate I don't care about the actual value as long as it's a value that ap...
Jackfruit asked 2/3, 2017 at 13:6

2

Solved

I'm trying to create an aggregate UDF, for example something like sum or median. The documentation and examples at https://docs.snowflake.net/manuals/sql-reference/udf-sql.html and https://docs.sn...

3

Let's say I'm using Django to manage a database about athletes: class Player(models.Model): name = models.CharField() weight = models.DecimalField() team = models.ForeignKey('Team') class Team...
Fumed asked 25/10, 2013 at 20:38

5

Solved

I want to aggregate the sum of a column, while tracking the presence of NULL values which signal an error condition. E.g., take the table numbers: # select * from numbers; n | l ------+----- 1 ...
Laynelayney asked 26/9, 2016 at 13:0

3

I have the following query to retrieve function definitions: select pg_get_functiondef from ( select pp.proname, pl.lanname,pn.nspname, pg_get_functiondef(pp.oid) from pg_proc pp inner join pg...
Monophonic asked 9/2, 2018 at 15:57

2

I have two tables with date-columns (year, month, day and a combination of the three called "stamp") and associated values (avalue). I need my function to return the ratio between two tab...
Kelleykelli asked 10/7, 2013 at 12:17

2

Solved

BigQuery with Legacy SQL has a pretty convenient QUANTILES function to quickly get a histogram of values in a table without specifying the buckets by hand. I can't find a nice equivalent in aggreg...
Colchicum asked 10/5, 2017 at 13:43

2

Solved

It seems like there is no native function for that purpose in Presto SQL. Do you know any way to efficiently aggregate a group and return its median?
Arbutus asked 23/9, 2020 at 14:41

4

Solved

Lets say I have a plant table: id fruit 1 banana 2 apple 3 orange I can do these SELECT * FROM plant ORDER BY id; SELECT * FROM plant ORDER BY fruit DESC; which does the obvious thing. But I...
Meaghanmeagher asked 27/10, 2012 at 10:23

9

Solved

The docs show how to apply multiple functions on a groupby object at a time using a dict with the output column names as the keys: In [563]: grouped['D'].agg({'result1' : np.sum, .....: 'result2' ...
Tambourine asked 25/1, 2013 at 20:26

5

Solved

I am trying to fetch the first and the last record of a 'grouped' record. More precisely, I am doing a query like this SELECT MIN(low_price), MAX(high_price), open, close FROM symbols WHERE date B...
Mckenney asked 4/9, 2009 at 14:20

7

Solved

The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (link text). Is there a reason Median is missing from the list? Implementing one see...
Parlando asked 3/6, 2009 at 0:51

4

I have 3 tables: users(id, account_balance) grocery(user_id, date, amount_paid) fishmarket(user_id, date, amount_paid) Both fishmarket and grocery tables may have multiple occurrences for the sa...
Fanaticize asked 17/9, 2012 at 17:7

3

Solved

I use Cosmos Db and I need results to be sorted by the results of a COUNT. Instead of sorting the results each time myself (or create a service for it), I prefer having the results sorted directl...
Yasminyasmine asked 21/11, 2019 at 10:59

6

Solved

This does not work: select count(distinct colA, colB) from mytable I know I can simply solve this by making a double select. select count(*) from ( select distinct colA, colB from mytable ) Is t...
Boswall asked 4/11, 2021 at 8:39

38

Solved

According to MSDN, Median is not available as an aggregate function in Transact-SQL. However, I would like to find out whether it is possible to create this functionality (using the Create Aggregat...
Litter asked 27/8, 2009 at 18:24

4

Solved

I need a standard deviation function in SQLite. I have found one here: http://www.sqlite.org/contrib?orderby=date but its part of an extension file to SQLite. I've never installed one of these b...

5

Solved

I am working with Postgres 9.4. I have a JSONB field: Column │ Type │ Modifiers ─────────────────┼──────────────────────┼──────────────────────────────────────────────────────────────────── id │...
Beltran asked 1/2, 2016 at 11:18

3

Solved

There is a set of users. A person can have multiple users, but ref1 and ref2 might be alike and can therefore link users together. ref1 and ref2 does not overlap, one value in ref1 does not exist i...
Overlong asked 26/5, 2023 at 8:28

3

Solved

I have the following table MyTable: id │ value_two │ value_three │ value_four ────┼───────────┼─────────────┼──────────── 1 │ a │ A │ AA 2 │ a │ A2 │ AA2 3 │ b │ A3 │ AA3 4 │ a │ A4 │ AA4 5...
Waterer asked 21/10, 2014 at 12:30

6

Solved

I'd like to perform division in a SELECT clause. When I join some tables and use aggregate function I often have either null or zero values as the dividers. As for now I only come up with this meth...
Heterotopia asked 16/7, 2013 at 15:56

3

Solved

I have a database using the following schema: CREATE TABLE IF NOT EXISTS `sessions` ( `starttime` datetime NOT NULL, `ip` varchar(15) NOT NULL default '', `country_name` varchar(45) default '',...
Oversleep asked 2/9, 2018 at 14:8

4

Solved

I have records related to dates: DATE AMOUNT 16.03.2013 3 16.03.2013 4 16.03.2013 1 16.03.2013 3 17.03.2013 4 17.03.2014 3 I know how to sum them up for each day, but how could I sum them up by ...
Idolum asked 12/8, 2014 at 8:34

5

Solved

I've got a list of Tokens which looks something like: [{ Value: "Blah", StartOffset: 0, EndOffset: 4 }, ... ] What I want to do is get a count of how many times each value occurs in the list ...
Navarra asked 4/4, 2013 at 15:54

1

I often have the need to perform custom aggregations on dataframes in spark 2.1, and used these two approaches : Using groupby/collect_list to get all the values in a single row, then apply an UDF...

© 2022 - 2024 — McMap. All rights reserved.