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
3 answers

Why do aggregates in subqueries have to be aggregated again?

I hope I've put the query together correctly below. I've simplified from something much, much bigger. But my question should be clear enough from the example. In the innermost query, nest1, let's say the results come back with three entries for…
tmoore82
  • 1,857
  • 1
  • 27
  • 48
0
votes
1 answer

Reference a FROM alias in HAVING

Newbie to sql here. I am trying to select only tuples whose values in one column are larger than the average of that column. The problem is, the relation I am working with is created in the FROM clause, because I need to add a transformation (and…
Spencer
  • 860
  • 8
  • 16
0
votes
0 answers

Best way to include aggregate data without reading entire table

I've built a query that uses a typical header/detail set of tables to report on records from the header table but provides aggregated data per header record from various types on the detail table. To get around the grouping issues I created a view…
Jeremie
  • 41
  • 1
  • 6
0
votes
1 answer

Querying amount of time level spent out of range

I have a table with that records the time and level of a tank. 12:00 | 85 12:01 | 77 12:02 | 78 12:03 | 82 12:05 | 79 12:06 | 75 12:07 | 85 etc. How could you write a query to get the amount of time the tank was below 80 throughout the day? I am…
user1904766
  • 49
  • 1
  • 6
0
votes
2 answers

Kendo - Grid - Custom Aggregate in FooterTemplate

My understanding is that Kendo does not support custom aggregates but you can call a function in the footerTemplate. That function then can provide calculations on the data and can even reference kendo defined aggregates. So, for…
James
  • 2,876
  • 18
  • 72
  • 116
-1
votes
1 answer

Trouble properly aggregating data with SQL

Im currently working on the second part of a two part exercise and am having trouble figuring out how to show the average number of films per state from a dvd rentals database. The question I am trying to address is: For each US state, show the…
-1
votes
1 answer

Postgres SQL aggregates query in BigQuery?

For Below Postgres SQL query, I do use PIVOT in BigQuery, beside PIVOT, any other method for such query in BigQuery? -- Postgres SQL -- SELECT Apple, Orange, Lemon, CASE WHEN Apple >= 50 THEN 1 ELSE 0 END AS…
Sola
  • 1,512
  • 4
  • 15
  • 31
-1
votes
1 answer

Details about Aggregates and where to use Aggregates

I read many articles and watched videos on youtube about aggregates but every time I am getting more confused by them. So please describe in detail with a specific example. I understood little about that is it is a collection and it can used in…
ARJUN PATEL
  • 67
  • 1
  • 1
  • 5
-1
votes
1 answer

SQL query to aggregate records

I have four tables: supplier, products, sales and sale_products. The suppliers and products table are associated in a one-to-many relationship, whereby a supplier can own multiple products and a product belongs to a single supplier. The products and…
-1
votes
1 answer

Add column of customer's past purchase total at time of current purchase and find rate of purchases that are from a returning customer - SQL

I am working with a table containing the purchase history for a shop. There is a purchase id, a date column and a customer id. I am trying (without much success so far) to do two things: Add a column which for each purchase tells how many purchases…
R_Mor88
  • 1
  • 2
-1
votes
2 answers

How to query SQL Server database to get a sum of time differences but only if they are less than 2 min different

I have the following queried data which is: SELECT * FROM MYTABLE WHERE tagid = '65' Output: tagid floatvalue t_stamp ------------------------------- 65 25.51477051 1455897455214 65 35.71407318 1455897485215 65 …
Xgrunt24
  • 25
  • 1
  • 4
-1
votes
5 answers

SQL SUM some COUNTS

If I have a table like this: FRUIT ------------------------ GRANNY SMITH BANNANA CHERRY RED DELICIOUS DURIAN FIG GRAPE LIME ORANGE BRAEBURN TANGERINE GRANNY SMITH ORANGE ORANGE GRANNY SMITH LIME FIG FIG GRANNY SMITH BRAEBURN And I want to produce…
Chuck
  • 3
  • 4
-2
votes
2 answers

T-SQL Not Performing Arithmetic Calculation of Aggregates Correctly

I have a table variable that stores the average times for two separate sub tasks that is grouped by employee. I need to add a record that stores the calculated weighted averages for those two tasks for the entire company. I added a column that…
W.Harr
  • 303
  • 1
  • 4
  • 15
-2
votes
1 answer

Grouping by similar categories over time

I looked around for awhile, but couldn't find anything. I have a table that looks like this: DATE | Shift | Parts Used 1/1/15 1:15.....1........1 1/1/15 2:06.....1........2 1/1/15 3:45.....1........3 1/1/15 7:33.....2........1 1/1/15…
user1904766
  • 49
  • 1
  • 6
1 2 3
11
12