Questions tagged [aggregate]

Combining multiple data points into a single data point. This usually is used in reference to SQL and usually to an aggregate function of some sort.

Combining multiple data points into a single data point. This usually is used in reference to SQL and usually to an aggregate function of some sort.

Aggregate functions return a single value per row based on a group of rows. Common examples include COUNT and SUM.

627 questions
36
votes
4 answers

Use of HAVING without GROUP BY in SQL queries

In order to use HAVING in SQL queries , must there be a GROUP BY to aggregate the column names? Are there any special cases where it is possible to use HAVING without a GROUP BY in SQL queries? Must they co-exist at the same time?
Computernerd
  • 493
  • 1
  • 5
  • 8
4
votes
1 answer

Why is the sum() of zero numbers not zero?

For the following query SELECT sum(c) FROM (SELECT 1 c WHERE false) t; I thought it takes the sum of zero numbers, and therefore should return 0. (Similarly, I expect, e.g. an array aggregate function to return an empty array on zero…
tinlyx
  • 3,540
  • 13
  • 46
  • 72
1
vote
1 answer

select rows where values equal the result of count(*) group by?

I have a table like this: Each keyword should have 4 pieces of data. I want to select the keywords that have less than 4 pieces of data (less than 4 rows). I used select count(*) from mytable group by keyword to achieve something like this: how…
Rick
  • 115
  • 6
0
votes
1 answer

SQL - Add column if match else, on aggregate data

I have an order table that roughly looks like this |Customer id |Date | revGBP |orderID |GiftOrder | --------------------------------------------------------------------- |1 |1-9-2014 |350 |1 | gift …
0
votes
1 answer

Choose record based on varying condition

I have a table that a primary key that can have one to two different status' associated with it. It looks like this: Key Status 123 Book 123 Change 122 Book 121 Book 121 Change If there is a record that has status of 'Change' then I only want to…