Questions tagged [aggregates]

Aggregate functions, typically found in SQL, derive summary values from multiple rows in a single column.

An aggregate, more commonly known as an aggregate function, is a means to examine the values found in multiple rows from a single column. These are grouped together as input on certain criteria to form a single value of more significant meaning or measurement, such as a set, a bag or a list. Aggregates are usually found in SQL.

179 questions
1
vote
2 answers

Aggregate query in same select statement

I have a select statement which is returning me 5 columns (and it is taking 1-2 minutes) one column in this is color (i.e. only three colors Red, Blue and Yellow). Now I want to show the count of the number of rows having Red, Number of rows having…
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206
1
vote
2 answers

Multi-aggregate, Multi-Filter, Single Table SQL

The following simulated table contains order details where cust_nbr represents the order number. I'm trying to find where if an order contains an item_nbr 90000, I need to know if the price for 90000 is greater than the sum of the other items plus…
Donna Panzarotti
  • 63
  • 2
  • 2
  • 8
1
vote
0 answers

I have to apply geoNear pipeline on location but have to filter users? How this will be achieved?

I am filtering users based on some attributes in the user collection and based on coordinates present in the location collection as in the below code. I have to Filter the location radius after the match pipeline because it will reduce the number of…
1
vote
2 answers

Postgres, CREATE AGGREGATE, accessing index and row count inside aggregate function for [non]oxford comma text

The goal is a custom aggregate function made with CREATE AGGREGATE called string_agg_oxford; it is an aggregate function that works similar to string_agg except it is smart enough to know how many items it is aggregating so that it can place "and"…
RichardForrester
  • 1,048
  • 11
  • 19
1
vote
0 answers

Is one row on correct for 'SELECT (SELECT SUM(t.val)) FROM mytable t'

Postgres and some online SQL engines return just one row for the SELECT: CREATE TABLE mytable(val INTEGER); INSERT INTO mytable VALUES (1), (2), (3), (NULL); SELECT (SELECT SUM(t.val)) FROM mytable t; The result is: 6 Does it correspond to the…
VladS24
  • 11
  • 1
1
vote
1 answer

How to find maximum, latest and average profit in sql

I have a table where i have user_id, item_id , profit_date and profit as a column. what i want is avg profit, maximum profit and latest profit for each user and item. i am able to find max and avg but stuck in finding latest profit because for this…
mr analyst
  • 79
  • 6
1
vote
2 answers

vhdl: Why is aggregate assignment not allowed in this context?

I am trying to use aggregate assignments within a conditional assignment statement in the lines labelled "PROBLEMATIC LINE" in the following code implementation for a priority encoder module. library ieee; use ieee.std_logic_1164.all; entity…
First User
  • 704
  • 5
  • 12
1
vote
1 answer

Strategy for updating huge entity's collection that belongs to Aggregate Root

I'm stuck with a specific scenario regarding Aggregates and not breaking business invariants. I've two entities, let's call them Order and OrderItem. Both entities belong to an aggregate with Order as Aggregate root. When I need to update one…
Alex29
  • 1,211
  • 2
  • 10
  • 20
1
vote
2 answers

How to identify non-identical values being aggregated with COUNT()?

I have a table containing three columns: city ID, language code and city: city_id | language_code | city ---------------------------------- 1 | en | London 1 | es | Londres 1 | pt | Londres 2 …
Chris Kobrzak
  • 1,044
  • 14
  • 20
1
vote
0 answers

Interactive altair chart that can change between monthly and yearly aggregates

I have a time series dataset and I wanted to plot line charts that display monthly and yearly changes.Some code provided below as an example. But instead of making two static charts, I'd like to have one interactive chart that allows me to change…
shimiao
  • 81
  • 4
1
vote
2 answers

Apply column filter on summed columns in DB2

I have the following DB2 table: COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE COLUMN_TEXT DMPROD -2 CHAR () FOR BIT DATA 35 Product Code DMPTYP -2 CHAR () FOR BIT DATA 1 Period Type DMTYPE -2 CHAR () FOR BIT DATA 6 Type of…
bran
  • 85
  • 2
  • 8
1
vote
1 answer

Generate a list of active users who haven't logged into the system in the last 60 days

I'm trying to generate a list of active users who haven't logged into the system in the last 60 days. The table records all attempts so I need to filter by users who are Active (in the employee profile table) and don't have recent login entries in…
Aaron Duff
  • 11
  • 1
1
vote
1 answer

Aggregate in case statement with "not a GROUP BY expression" error

Why do I get "not a GROUP BY expression" error when I include below case statement in my query even though the case statement below uses an aggregate which is not allowed in GROUP BY? When I include the case statement in the GROUP BY I, of course,…
Adrian
  • 55
  • 7
1
vote
1 answer

Correct size of DDD aggregate in java project (spring boot)

I'm designing modules in web chess game and I feel confused in some case. I've separated several modules (aggregates): Profile (id, name, photo, isActive) Ranking (id, value, list of ranking changes (date, ranking difference, opponent…
Bambelal
  • 179
  • 1
  • 2
  • 13
1
vote
1 answer

Aggregate Ordering with Named Association

I'm struggling to understand the bit order of an aggregate, especially since I've used name association. The buses are defined as (0 to 3) and (3 downto 0), but since I've used named association, why are the outputs z3..0 and ob3..0 the reverse of…
tim
  • 482
  • 3
  • 12