5,918 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
99
views
Calculate percent of total per firm and filter firms above 50%
I'm trying to calculate the percentage contribution of each firm to the total amount across all firms.
Database:
google-bigquery
What I need (desired output):
Sum usde_haircut_amt per firm
Compute ...
3
votes
3
answers
164
views
How to retrieve a sub-array from result of array_agg?
I have a SQL table in postgres 14 that looks something like this:
f_key
data1
data2
fit
1
{'a1', 'a2'}
null
3
1
{'b1', 'b2'}
{'b3'}
2
2
{'c1', 'c2'}
null
3
Note that data1 and data2 are arrays.
I need ...
2
votes
2
answers
147
views
Example of partial aggregation
As Postgresql documentation states in # 36.12.4. Partial Aggregation aggregate functions can support partial aggregation.
To do this with custom aggregate function as again the documentation says we ...
0
votes
1
answer
114
views
Aggregate function for bit-wise OR [duplicate]
In SQL Server 2022, is there an aggregate function for doing a bit-wise OR against a particular column?
-- Example table, data and output to show the different flags
DECLARE @TEST TABLE (FLAGS TINYINT)...
2
votes
2
answers
114
views
postgres jsonb array aggregate functions
I have a table with data on user applications. It contains several fields: employee_id text, date date, app_info jsonb.
+-------------+------------+------------+
| employee_id | date | app_info ...
-1
votes
2
answers
193
views
Calculate SUM over a primary key and between dates
My query:
SELECT
c.CustID,
o.OrderID,
SUM(ol.Qty * ol.Price) AS SUMOrder,
AVG(SUM(ol.Qty * ol.Price)) OVER (PARTITION BY c.CustID) AS AVGAllOrders,
COUNT(*) AS Countorders,
SUM(...
1
vote
0
answers
112
views
A User Defined Aggregated Function fails to shape a Map<K, C> field, where C is an object coming from many rows
Edit: Progressing into this problem analysis, the management of the dataset nested values with tools that Spark offers since 3.1.x seems required.
→ It's my manner of filling nested objects hold by ...
4
votes
5
answers
200
views
Query to find the product name which has a continuous increase in sales every year
Product table with columns - PRODUCT_ID PRODUCT_NAME
PRODUCT_ID
PRODUCT_NAME
100
NOKIA
200
IPHONE
300
SAMSUNG
400
OPPO
Sales table with columns - SALE_ID PRODUCT_ID YEAR QUANTITY Price
SALE_ID
...
1
vote
1
answer
55
views
How to write a query with aggregates of json_array_elements in jOOQ
I have this query:
SELECT organisation_id,
count((j->>'invoiceId')) AS count,
sum((j->>'advanceAmount')::numeric(20,4)) AS sum
FROM runs
LEFT JOIN jsonb_array_elements(...
0
votes
0
answers
94
views
PySpark with aggregations failing
I have a 106M dataframe with nested columns, that is, I have a few columns where the values are {[1,2,3,4,5], <timestamp>, 1, 2 ,3}. I'm trying to add a few more columns using when, then do an ...
1
vote
1
answer
125
views
Extended condition of aggregating functions SQL
I need group speed by ram and return MAX(speed), where at least one NULL in speed values will return NULL.
ram
speed
128
600
128
600
128
750
128
750
128
800
128
900
32
400
32
NULL
32
500
64
450
64
500
...
0
votes
2
answers
65
views
SQL row-wise comparison within group
I am trying to compute the number of events that take place within 30 minutes of one another (variable n_within_30) on the same date and in the same location.
I have tried to partition and group by ...
0
votes
1
answer
86
views
BigQuery aggregations on different level by grouping sets
I need to create an aggregation for each housing type (column type) for each destination.
There is a hierarchy (product->sub_product) and (category->sub_category) and also product can have ...
0
votes
0
answers
52
views
How to get count of unique users [duplicate]
Have the following tables:
Projects:
id
name
1
Project 1
2
Project 2
3
Project 3
Assignments:
id
project_id
user_id
1
1
1
2
1
3
3
1
2
4
2
1
5
3
1
6
3
2
Users:
id
name
1
User 1
2
User 2
3
User 3
I'm ...
0
votes
0
answers
16
views
Finding the minimum date from a set of dates [duplicate]
I'm having an issue with my assignment where it's giving me more than one "minimum" date.
The problem is to create a table variable that shows the earliest invoice sent by each vendor, ...