HAVING in SQL _ 1Keydata

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

3/2/2016 HAVING in SQL | 1Keydata

SQL HAVING

SQL Data Warehousing CSS PHP HTML Database Normalization

SQL Tutorial
Basic SQL Commands
| COMPOSE

SQL SELECT
SQL DISTINCT
SQL WHERE SQL > SQL Commands > Having
SQL AND OR
Another thing people may want to do is to limit the output based on the corresponding sum (or any other aggregate funct
SQL IN
we might want to see only the stores with sales over $1,500. Instead of using the WHERE clause in the SQL statement, tho
SQL BETWEEN
the HAVING clause, which is reserved for aggregate functions. The HAVING clause is typically placed near the end of the S
SQL Wildcard SQL statement with the HAVING clause may or may not include the GROUP BY clause. The syntax for HAVING is,
SQL LIKE
SQL ORDER BY SELECT ["column_name1"], Function("column_name2")
SQL GROUP BY FROM "table_name"
SQL HAVING [GROUP BY "column_name1"]
SQL ALIAS HAVING (arithmetic function condition);
SQL AS
SQL SELECT UNIQUE Note: We may select zero, one, or more columns in addition to the aggregate function. If we select zero column, there is n
SQL JOIN GROUP BY clause.
SQL INNER JOIN
In our example, table Store_Information,
SQL OUTER JOIN
SQL LEFT OUTER JOIN Table Store_Information
SQL CROSS JOIN
SQL INSERT INTO Store_Name Sales Txn_Date
SQL INSERT INTO SELECT Los Angeles 1500 Jan-05-1999
SQL UPDATE San Diego 250 Jan-07-1999
SQL DELETE FROM Los Angeles 300 Jan-08-1999
Advanced SQL Boston 700 Jan-08-1999
SQL UNION
SQL UNION ALL we would type,
SQL Inline View
SELECT Store_Name, SUM(Sales)
SQL INTERSECT
FROM Store_Information
SQL MINUS
GROUP BY Store_Name
SQL LIMIT HAVING SUM(Sales) > 1500;
SQL TOP
SQL Subquery Result:
SQL EXISTS
SQL CASE Store_Name SUM(Sales)
SQL DECODE Los Angeles 1800
SQL AUTO INCREMENT
SQL IDENTITY
SEQUENCE & NEXTVAL Intex Aqua i7 in a very good condition...
SQL Functions Rs. 5,000 Get Best Deals. Quick, Easy & Free!
SQL Average Quikr.com
SQL COUNT
SQL MAX
SQL MIN Exercises
SQL SUM
SQL ROUND For these exercises, assume we have a table called Region_Sales with the following data:

String Functions Table Region_Sales


SQL CAST
SQL CONVERT Region Year Orders Total_Sales
SQL CONCATENATE West 2013 1560 325000
SQL SUBSTRING West 2014 1820 380000
SQL INSTR North 2013 790 148000
SQL TRIM North 2014 995 185000
http://www.1keydata.com/sql/sqlhaving.html 1/2
3/2/2016 HAVING in SQL | 1Keydata
North 2014 995 185000
SQL LENGTH
East 2013 1760 375000
SQL REPLACE
East 2014 2220 450000
SQL TO_DATE
South 2013 1790 388000
Date Functions
South 2014 1695 360000

1. Which of the following order is correct for a SQL statement?


a) SELECT...FROM...ORDER BY...WHERE...HAVING
b) SELECT...FROM...WHERE...ORDER BY...HAVING
c) SELECT...WHERE...FROM...HAVING...ORDER BY
d) SELECT...FROM...WHERE...HAVING...ORDER BY

2. What is the result of the following SQL statement?


SELECT Region, SUM(Orders) FROM Region_Sales GROUP BY Region HAVING SUM(Orders) > 2500;

3. What is the result of the following SQL statement?


SELECT Region, SUM(Orders) FROM Region_Sales WHERE Total_Sales < 385000 GROUP BY Region HAVING SUM(Orders) >

Show Answers

Next: SQL Alias

ODBC Drivers for MS SQL


Quick & secure access from Linux, Windows, OS X, & other Unix­like OS

Copyright © 2016 1keydata.com All Rights Reserved Privacy Policy About Contact

http://www.1keydata.com/sql/sqlhaving.html 2/2

You might also like