Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql grouping functions

MySQL Grouping Functions
AVG
MAX
BIT_AND
STD
BIT_OR
STDDEV
COUNT
SUM
GROUP_­CONCAT
VARIANCE
MIN
Comment

GROUPING function in mysql

/*
The GROUPING function is commonly used to replace 
the nulls that are generated by WITH ROLLUP with literal values. 
The IF function evaluates the expression in the first argument and returns
the second arguments if the expression is true and the third argument if
the expression is false.
#> If you want to display just the summary rows produced by the WITH ROLLUP
operatior, you can include one or more GROUPING functions in the HAVING clause.
*/
SELECT IF(GROUPING(invoice_date) = 1, 'Grand totals', invoice_date) AS invoice_date, 
	   IF(GROUPING(payment_date) = 1, 'Invoice date totals', payment_date) AS payment_date,
	   SUM(invoice_total) AS invoice_total,
	   SUM(invoice_total - credit_total - payment_total) AS balance_due 
FROM invoices
WHERE invoice_date BETWEEN '2018-07-24' AND '2018-07-31'
GROUP BY invoice_date, payment_date WITH ROLLUP; 
Comment

PREVIOUS NEXT
Code Example
Sql :: how to check common records in 2 table 
Sql :: create a plsql object 
Sql :: oracle list partitioned tables 
Sql :: Write a PL/SQL to print even numbers upto 100. 
Sql :: subquery in mysql 
Sql :: windows aggregate functions in postgresql 
Sql :: Unable to locate package libmysql-java 
Sql :: SQL SELECT TOP Equivalent in oracal 
Sql :: show sql property syntax for jpa. 
Sql :: select multiple tables mysql 
Sql :: split string and copy last element postgresql 
Sql :: create atable copy in pgsql 
Sql :: alter database datafile maxsize 32g 
Sql :: mysql inner join 
Sql :: mysql delete duplicate rows except one 
Sql :: neo4j command to run script file 
Sql :: date on sql 
Sql :: how to get last element sql 
Sql :: mysql create table 
Sql :: sql default 
Sql :: how to fetch data from database without last column 
Sql :: timestamp(0) postgresql 
Sql :: get first match in each group mysql query 
Sql :: advantages of stored procedures sql 
Sql :: cast in sql server 
Sql :: connect laravel to mysql on mac 
Sql :: ignore duplicate rows in sqlite 
Sql :: sql is not null 
Sql :: create domain sql 
Sql :: sql file in postgres with pgadmin 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =