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
0
votes
0 answers

Mongodb $geonear from joining two collections: Calculate distance from coordinates

We have mongodb collections users { _id: "1", location: { coordinates: [ -63, 42 ], type: "Point" }, name: "user one" }, { _id: "2", location: { coordinates: [ -83, 52 ], type: "Point" }, name: "user two" } { _id:…
user3419778
  • 856
  • 3
  • 8
  • 11
0
votes
2 answers

How can i write an equivalent sql query for pivot with complex aggregations in oracle database?

In spark we can provide complex aggregates with pivot. e.g. project.groupBy("mgr","job").pivot("job").agg(sum(project.col("salary")).alias("ss") * count("*").alias("c")) On below data i.e.…
Ashutosh
  • 75
  • 1
  • 10
0
votes
1 answer

DDD modeling aggregate with few invariants and many fields

I thinking about modeling aggregates, invariants, data etc. There is common advice to design aggregates to be small. I have problem a with correct splitting domain and simple CRUD. Let's assume that we have application where we are able to create…
Papub
  • 75
  • 1
  • 9
0
votes
1 answer

Oracle Group by only one column but select many columns

Object types: Theatre_t (tno:integer, nome:string, city:string, phone:string) Star_t (nome:string, gender:char(l), birthdate:date) Stars_nt table of Star _t Film_t (filmno:integer, title:string, language:string, director:string, budget:float,…
0
votes
1 answer

elasticsearch aggregates some values in a single field

I have some raw data { { "id":1, "message":"intercept_log,UDP,0.0.0.0,68,255.255.255.255,67" }, { "id":2, "message":"intercept_log,TCP,172.22.96.4,52085,239.255.255.250,3702,1:" }, { "id":3, …
ChaosFish
  • 62
  • 1
  • 8
0
votes
0 answers

filter result with $match and regular expressions inside $lookup

I have this Aggregation pipeline. I am able to get the data I need with additional function like sorting and pagination. I used $lookup to add documents I need from other collections. [ { '$match': { status: [Object] } }, { '$lookup': { from:…
JMA
  • 974
  • 3
  • 13
  • 41
0
votes
2 answers

Producing NULL Value related to AVG(field) in HAVING CLAUSE

Here is my table: There are Multiple Salaries under 61,000. The AVG Salary for Related table is 61K. If I write a query: SELECT `StaffID`, `Title`, `FirstName`, `LastName`, `DeptID`, `Salary` FROM `Staff` WHERE `Left` < '2018-00-00' AND…
CMCN
  • 1
  • 1
0
votes
1 answer

Filter query by count associated data CakePHP 3

I want to do a query on “Articles” but I only want the “Articles” which have two or more “Comments”. So I have to count “Comments” and use the count result in the where clause. I know the next code is wrong but it would be something like: $articles…
0
votes
2 answers

MySQL - aggregating and GROUP BY with subqueries

Is it possible to use GROUP BY to aggregate cells with subqueries? The database I'm working with contains customer order information (Order ID, Name, Address, Product, Option, etc). When a customer selects multiple options for a product they appear…
msklut
  • 61
  • 2
  • 7
0
votes
1 answer

Aggregate within an aggregate

I am trying to use multiple aggregates in a single select statement and am stuck on the one that's value is based off of another aggregate (Total revenue which is calculated by multiplying COUNT(TrackID) by Unit Price). I am not allowed to do CTEs…
Corina
  • 11
  • 5
0
votes
1 answer

Hive: Is there a way to get the aggregates of all the numeric columns existing in a table?

I have a table containing over 50 columns (both numeric and char), is there a way to get the overall statistics without specifying each column? As an example: a b c d 1 2 3 4 5 6 7 8 9 10 11 12 Ideally I would have something…
OanaB
  • 23
  • 5
0
votes
2 answers

Scala / MongoDB - removing duplicate

I have seen very similar questions with solutions to this problem, but I am unsure how I would incorporate it in to my own query. I'm programming in Scala and using a MongoDB Aggregates "framework". val getItems = Seq ( …
Chris
  • 785
  • 10
  • 24
0
votes
1 answer

How do I combine data values in R that were taken on the same date?

I have rainfall data in V10, and I'm trying to aggregate it so that I can get the rainfall totals for each date. Having trouble using the zoo/aggregate functions. Any help is appreciated- thanks. V1 V10 Date Dates 2019-02-10…
Aaron Sun
  • 1
  • 1
0
votes
1 answer

Grouping object columns in Python

I am doing some analysis by grouping specific site locations by countries. Here is the code part: results[["Site ID"]].groupby(["Country Code"]).sum() However this does not work because the column Site ID is an alphanumeric value in the form of…
0
votes
1 answer

sql multiple join (right. left, inner) to mongodb aggregate

//I have a sql like this SELECT x.attr1, p.attr2, p2.attr3, o.attr4, p2.attr5, a2.attr6 FROM TABLE_O o RIGHT JOIN TABLE_A a ON a.id = o.id AND a.id2 IS NULL LEFT JOIN TABLE_A a2 ON a2.id = o.id AND a2.id2 = a.id3 LEFT JOIN TABLE_P p ON a.id4 =…
sergioAJ
  • 11
  • 1