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

Table has duplicate data and can't get two aggregates functions to work in SQL Query

The problem is that the table "addresses" has multiple entries where a user has updated their address. I just need the latest one. I tried to use MAX(uPDATED_AT) in the "addresses" table but get an error. Well, I first wrote the code below and…
user4370644
2
votes
2 answers

count values with yes and not in sql statement

I have a table with data like this: USER NAME Timestamp EXECUTED CLOSED 1 user1 JOHN DOE 2015-11-23 12:50:45 Yes Yes 2 user1 JOHN DOE 2015-11-23 12:52:35 Yes Yes 3 user1 JOHN DOE 2015-11-23 12:53:52…
chan go
  • 137
  • 11
2
votes
1 answer

SparkSQL: conditional sum on range of dates

I have a dataframe like this: | id | prodId | date | value | | 1 | a | 2015-01-01 | 100 | | 2 | a | 2015-01-02 | 150 | | 3 | a | 2015-01-03 | 120 | | 4 | b | 2015-01-01 | 100 | and I would love to do a groupBy…
lilloraffa
  • 1,367
  • 3
  • 17
  • 22
2
votes
2 answers

How can I divide grouped data by date in do columns

I have a data set that I would like to group by a customer code and for each code I would like to Sum transaction totals between the dates of a month and have each month become a separate column. I can make this dynamic my main concern is…
Allen Craig
  • 127
  • 10
2
votes
1 answer

Aggregating values into a table type within a GROUP BY query

Suppose you have a table (in Oracle): CREATE TABLE CUSTOMER ( customer_id NUMBER, gender CHAR(1) ); And suppose you have a table type: CREATE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER; Is it possible to write a GROUP BY query such that,…
Adam Paynter
  • 46,244
  • 33
  • 149
  • 164
2
votes
1 answer

converting xml to json using postgresql

I am working on converting XML to j son string using the PostgreSQL. we have attributecentric XML and would like to know how to convert it to j son. Example XML: Need to get the j son as follows: { "ROOT":…
Azzu
  • 23
  • 1
  • 3
2
votes
1 answer

PostgreSQL search column for like strings

I'm pretty new to PostgreSQL right now and am trying to search through a column and find where in that column duplicate strings exist. For example, if I have the following table: Col_1 Col_2 Col_3 1 cat 45 2 dog 67 3 bird …
TheVideotapes
  • 383
  • 2
  • 3
  • 9
2
votes
1 answer

Grouping sets columns in aggregate arguments and NULL replacement

There are many grouping sets examples on the internet like query Q1 in the example below. But query Q2 is different because A2 is a grouping column and it is used as the argument to SUM(). Which one of the following is correct for Q2 according to…
Ben C
  • 658
  • 6
  • 18
2
votes
1 answer

Converting daily data in to weekly in Pandas

I have a dataframe as given below: Index Date Country Occurence 0 2013-12-30 US 1 1 2013-12-30 India 3 2 2014-01-10 US 1 3 2014-01-15…
Nithin Das
  • 364
  • 1
  • 5
  • 14
2
votes
1 answer

MySQL joins with WHERE clause

I have 2 queries which display 2 different values but the results from one query are unexpected. Query1: SELECT SUM(T.amount_reward_user) AS total_grouping FROM fem_user_cards UC LEFT JOIN fem_transactions T USING(card_number) LEFT…
Deepak
  • 6,684
  • 18
  • 69
  • 121
2
votes
2 answers

Aggregate functions return wrong values when joining more tables

I want to display all customers and their addresses and the number and total sum of their orders. My query looks like this: select *, sum(o.tota), count(o.total) from customer c natural join orders o group by c.custId; which works fine. but if I…
codymanix
  • 28,510
  • 21
  • 92
  • 151
2
votes
4 answers

When I read other posts about this, I still can't see the difference in SQL between GROUP BY and ORDER BY. What is it?

I've started my own thread on this question so as to have less overhead from posting it on someone else's thread. I have trouble understanding in SQL what the difference is between GROUP BY and ORDER BY. I know there have been threads made about…
Panzercrisis
  • 4,590
  • 6
  • 46
  • 85
2
votes
1 answer

Guide me in writing aggregation (groupBy,orderBy) Lua script for Aerospike

I have a following lua script that groups the data with 'sensorType' and print 'clientId' in each group of 'sensorType'. function orderby(touples) local function mapper(rec) local element = map() element["clientId"] = rec["clientId"]; …
Hafsa Asif
  • 371
  • 1
  • 5
  • 11
2
votes
1 answer

Stop the procedure when the population of agents have the same variable in Netlogo

I am trying to stop my simulation when most of the population of agents have the same own variable value but I really don´t know ho to do it. Here is my code for the creation and the procedure of my model: breed [birds bird] birds-own [high] …
Paul
  • 189
  • 6
2
votes
1 answer

Merge multiple result tables and perform final query on result

I have a function returning table, which accumulates output of multiple calls to another function returning table. I would like to perform final query on built table before returning result. Currently I implemented this as two functions, one…