Learning SQL by Alan Beaulieu
Author:Alan Beaulieu [Alan Beaulieu]
Language: eng
Format: epub
Tags: COMPUTERS / Database Management / Data Mining
ISBN: 9780596555580
Publisher: O'Reilly Media
Published: 2009-04-10T16:00:00+00:00
In some cases, the all operator is a bit more natural. The next example uses all to find accounts having an available balance smaller than all of Frank Tucker’s accounts:
mysql> SELECT account_id, cust_id, product_cd, avail_balance -> FROM account -> WHERE avail_balance < ALL (SELECT a.avail_balance -> FROM account a INNER JOIN individual i -> ON a.cust_id = i.cust_id -> WHERE i.fname = 'Frank' AND i.lname = 'Tucker'); +------------+---------+------------+---------------+ | account_id | cust_id | product_cd | avail_balance | +------------+---------+------------+---------------+ | 2 | 1 | SAV | 500.00 | | 5 | 2 | SAV | 200.00 | | 10 | 4 | CHK | 534.12 | | 11 | 4 | SAV | 767.77 | | 14 | 6 | CHK | 122.37 | | 19 | 8 | SAV | 387.99 | | 21 | 9 | CHK | 125.67 | | 25 | 10 | BUS | 0.00 | +------------+---------+------------+---------------+ 8 rows in set (0.17 sec)
Here’s the data returned by the subquery, which consists of the available balance from each of Frank’s accounts:
mysql> SELECT a.avail_balance -> FROM account a INNER JOIN individual i -> ON a.cust_id = i.cust_id -> WHERE i.fname = 'Frank' AND i.lname = 'Tucker'; +---------------+ | avail_balance | +---------------+ | 1057.75 | | 2212.50 | +---------------+ 2 rows in set (0.01 sec)
Frank has two accounts, with the lowest balance being $1,057.75. The containing query finds all accounts having a balance smaller than any of Frank’s accounts, so the result set includes all accounts having a balance less than $1,057.75.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Access | Data Mining |
Data Modeling & Design | Data Processing |
Data Warehousing | MySQL |
Oracle | Other Databases |
Relational Databases | SQL |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7456)
Learning SQL by Alan Beaulieu(4984)
Weapons of Math Destruction by Cathy O'Neil(4426)
Blockchain Basics by Daniel Drescher(2563)
Pandas Cookbook by Theodore Petrou(2312)
How The Mind Works by Steven Pinker(1919)
Mastering Python for Finance by Unknown(1781)
Python Natural Language Processing by Jalaj Thanaki(1744)
Python Machine Learning Case Studies by Danish Haroon(1647)
Building Machine Learning Systems with Python by Richert Willi Coelho Luis Pedro(1615)
Python for Finance: Analyze Big Financial Data by Yves Hilpisch(1411)
Mastering Python Data Visualization by Kirthi Raman(1406)
Everybody Lies by Seth Stephens-Davidowitz(1402)
Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability by Steve Krug(1391)
Data Science for Business by Foster Provost & Tom Fawcett(1341)
Mastering Machine Learning Algorithms by Giuseppe Bonaccorso(1313)
Pro Power BI Desktop by Adam Aspin(1280)
Database Reliability Engineering: Designing and Operating Resilient Database Systems by Campbell Laine & Majors Charity(1257)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(1256)
