Questions tagged [aggregate-functions]

Aggregate functions are a subset of SQL functions that compute a single value from multiple input rows, mostly used in `SELECT` queries with a `GROUP BY` clause. Practically all modern RDBMS feature aggregate functions. Typical examples include `COUNT()`, `SUM()`, `MIN()`, `MAX()`, and `AVG()`.

Aggregate functions are a subset of SQL functions that compute a single value from multiple input rows, mostly used in SELECT queries with a GROUP BY clause. Practically all modern RDBMS feature aggregate functions.

Typical examples include COUNT(), SUM(), MIN(), MAX(), and AVG().

5778 questions
2
votes
1 answer

Pandas Pivot and Summarize For Multiple Rows Vertically

Given the following data frame: import numpy as np import pandas as pd df = pd.DataFrame({'Site':['a','a','a','b','b','b'], 'x':[1,1,0,1,0,0], 'y':[1,np.nan,0,1,1,0] }) df Site y …
Dance Party
  • 3,459
  • 10
  • 42
  • 67
2
votes
1 answer

Filter Realm with count() in Java

I'm using latest Realm (0.90.0) and have two RealmObjects Event and Game in one-to-many relationship: public class Event extends RealmObject { ... private RealmList games; } I wish to filter Events with one of the conditions that…
Draško
  • 2,119
  • 4
  • 41
  • 73
2
votes
2 answers

string aggregate group and count on a value

I have table like this. | table | | class_id| name | gender | +---------+---------+----------+ | 1 | Jane | F | | 1 | John | M | | 1 | Tom | M | | 1 | Bob …
lokmancetin
  • 25
  • 1
  • 5
2
votes
1 answer

Aggregate calculations from 2 separate tables

I have a SALES_RECEIPT table and a (sales) RETURNS table that both have REP_ID as a foreign key from the SALES_REP table. I want to sum total sales and total returns for each sales rep and calculate the commission from the sales and the lost…
2
votes
1 answer

Average count of elements in a set in hive?

I have two columns id and segment. Segment is comma separated set of strings. I need to find average number of segments in all the table. One way to do it is by using two separate queries - A - select count(*) from table_name; B - select count(*)…
BlitzKrieg
  • 791
  • 8
  • 15
2
votes
1 answer

How could I aggregate a description column?

I've written a SQL query that calculates stock totals in each of our warehouses, as follows. SELECT InventoryItem.ItemName as 'Part Number', InventoryItemDescription.ItemDescription as 'Description', InventoryStockTotal.UnitsInStock as 'In…
Brendan Gooden
  • 1,460
  • 2
  • 21
  • 40
2
votes
2 answers

How do i get max salary row , group by country

------------------------------------------------ country | salary | name | adress ------------------------------------------------ India | 10000 | ch1 | something japan | 20000 | ch2 | nothing india | …
jaffer
  • 23
  • 6
2
votes
1 answer

One to Many Join with Aggregate Function (Max)

I have two tables. Table 1: +---------+---------+ | Lead_ID | Deal_ID | +---------+---------+ | 2323 | null | | 2324 | 1199 | | 2325 | null | | 2326 | null | | 2327 | 1080 | +---------+---------+ Table…
dsm309
  • 69
  • 1
  • 6
2
votes
3 answers

How to edit this mySQL so as to combine the rows of the same id into 1 instead of 3?

The following mySQL query gets data from 2 tables, alerts_data and alerts_list. The first table has the data of an alert, and the second has the description of the alert. So in the alerts_data there are multiple rows with the same alerts_data_id…
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
2
votes
1 answer

MySQL: Aggregate function: group by joined variable

I thought I had this down, but it looks like I'm doing something wrong, and I can't be certain what. UPDATE: I believe the error has something to do with a connection between the customer table and the order_details table. Not sure what exactly it…
Sierra
  • 327
  • 4
  • 11
2
votes
4 answers

What is the counterpart for SUM() in SQL Server?

In SQL Server you can do sum(field1) to get the sum of all fields that match the groupby clause. But I need to have the fields subtracted, not summed. Is there something like subtract(field1) that I can use in stead of sum(field1) ? For example,…
GuidoG
  • 11,359
  • 6
  • 44
  • 79
2
votes
1 answer

pull averages and counts based on a set of calculated time ranges mysql

I have 2 tables - sentiment & comments - that I'm trying to join averages and counts from based on a set of derived time ranges in mysql. Here's what I have that works individually: SELECT ROUND(AVG(sentiment.sent_value)) AS sentiment, …
aw8
  • 63
  • 4
2
votes
2 answers

Group rows into two types depending on a value in column

I have a table: ------------------------------------------ Uid | mount | category ----------------------------------------- 1 | 10 | a 1 | 3 | b 3 | 7 | a 4 | 1 | b 4 | 12 | a 4 | 5 | b 1 | 2 …
bandungeuy
  • 378
  • 4
  • 19
2
votes
2 answers

MySQL Query Problem with Alias and Aggregate Functions

I have a troublesome MySQL query as follows: SELECT camera_id, ((avg(low_price) + avg(high_price)) / 2) as avg_price FROM camera_general, camera_products WHERE camera_id = ir_camera_id AND dp_post_dt IS NOT NULL AND dp_post_dt NOT LIKE '0000%' AND…
Yazmin
  • 1,154
  • 5
  • 17
  • 34
2
votes
2 answers

Why is this T-SQL query throwing an "aggregate function" error message?

I am using SQL Server 2014 and I have the following SQL query which runs fine and gives the following output: SELECT [PropertyCode], [BkgLeadTime], COUNT([Bkg Lead Time]) AS 'BLT COUNT' FROM BOOKINGLEADTIME_CTE GROUP BY …
user3115933
  • 4,303
  • 15
  • 54
  • 94