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 :: what i ssql 
Sql :: mysql error 1215 
Sql :: How Much Space is PL/Scope Data Using? 
Sql :: fetch second word from a string in ms sql 
Sql :: comma seperated join mssql 
Sql :: How to take sum of column with same id in "JPQL?" 
Sql :: do you know sql 
Sql :: To Create directory 
Sql :: alter check command 
Sql :: undefined get_magic_quotes_gpc() in sqlite 
Sql :: add sqlcmd to path linux 
Sql :: postrgres trunc 
Sql :: SQL Copy Selected Columns Only 
Sql :: how to fetch unique records from two tables 
Sql :: convert xml data to table format sql server 
Sql :: oracle exchange partition 
Sql :: repeatable read trong sql server 
Sql :: postgres docs /copy metacomand 
Sql :: mysql BEFORE UPDATE INSERT 
Sql :: Limit in access query 
Sql :: liquibase default-schema in sql 
Sql :: which lock mode is not available in sql 
Sql :: how to see password mysql vestacp 
Sql :: oracle transaction rollback not working 
Sql :: sql server and spring boot api 
Sql :: in sql developer where equal queres 
Sql :: postgresql get tables where column is foreign key 
Sql :: mysql find the row ites of the hoghest value at on column 
Sql :: postgresql createdb 
Sql :: Data type and their numeric form 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =