How to Use CUBE Operator with HAVING Clause in SQL
In this article I am going to explain how to Use CUBE Operator with HAVING Clause in SQL.
Introduction
In this article I am going to explain how to Use CUBE Operator with HAVING Clause in SQL. GROUP BY clause is used to groups the rows of result set based on one or more columns or expression. GROUP BY clause is used in SELECT statements that include aggregate functions.
WITH CUBE operator is used in GROUP BY clause to add summary rows to final result set. Each combination of groups specified in GROUP BY clause is summarized by CUBE operator. CUBE Operator also provide a another feature by which it it summaries the entire result set at the end of result set.
Example
select vendorid,sum(invoicetotal) as invo_total
from mcninvoices
group by vendorid with CUBE
|
Output
Example
select vendorname,invoiceid,sum(invoicetotal) as invo_total
from mcninvoices join mcnvendors
on mcninvoices.vendorid = mcnvendors.vendorid
where invoicetotal > 500
group by vendorname,invoiceid with CUBE
|
Output