Download presentation
Presentation is loading. Please wait.
Published byClemence Walton Modified over 8 years ago
1
Chapter 10 - EQUALITY AND INEQUALITY PREDICATES MeaningPredicate Equal to= Not equal to<> Less than< Less than or equal to<= Greater than> Greater than or equal to=> Business TaskTechnical Solution Find a customer based on the exact entry of his/her last name. SELECT * FROM Customers WHERE (lastname = "Delaney") Find orders for which the shipping cost was more than $35. SELECT OrderID, OrderDate, ShippedDate, ShippingCost FROM Orders WHERE ShippingCost > 35 ORDER BY ShippingCost DESC Select all orders with an order date later than June 30 2012. SELECT OrderID, OrderDate, ShippedDate, ShippingCost FROM Orders WHERE OrderDate > #6/30/2012# ORDER BY OrderDate
2
Chapter 11 - BETWEEN OPERATOR The BETWEEN AND OPERATOR is used to retrieve a set of data within two boundaries (usually dates or numbers). The BETWEEN AND operator is inclusive, that is the boundaries will be included in the result set. Business TaskTechnical Solution Find products in our inventory with prices between $15 and $18. SELECT productname, productunitprice FROM products WHERE productunitprice BETWEEN 15 AND 18 ORDER BY productunitprice Find orders placed within a date range.SELECT OrderID, orderdate, shippeddate FROM orders WHERE orderdate BETWEEN #6/15/2012# AND #8/15/2013# ORDER BY orderdate DESC Find orders placed within a range of years.SELECT OrderID, orderdate, shippeddate FROM orders WHERE year(orderdate) BETWEEN 2013 AND 2014 ORDER BY orderdate DESC
3
Chapter 12 - IN OPERATOR Business TaskTechnical Solution Create a report of customers from multiple cities SELECT lastname, firstname, city FROM customers WHERE city in ('New York', 'Boston', 'Chicago', 'Los Angeles', 'Dallas') Create a report of products based on specific prices SELECT productname, quantityperunit, productunitprice FROM products WHERE productunitprice in (15, 19, 22, 23, 42) Generate a report of orders in which there is at least one non-discounted product SELECT orderid, orderdate, shippeddate FROM orders WHERE orderid IN (SELECT orderid FROM ProductsOrders WHERE (Discount) =0) The primary role of the IN operator is to participate in search conditions for filtering records It takes the place of multiple OR operators. It is indispensable with subqueries
4
Chapter 13 - DISTINCT PREDICATE The DISTINCT predicate is used to eliminate duplicate rows from the results of a SELECT statement. It belongs to a set of four predicates (ALL, TOP, DISTINCT, DISTINCTROW) Business TaskTechnical Solution Find all cities in which we have customers Distinct on one column SELECT city FROM customers SELECT DISTINCT city FROM customers Finding unique customer names in various states Distinct with multiple columns If we include the DISTINCT clause such as: SELECT DISTINCT firstname, state FROM customers Complete the first four examples only
5
Chapter 14 – The TOP PREDICATE The top predicate by itself does not produce useful results. We can use it with the order by clause however for useful information. Business TaskTechnical Solution Top with numbers – Look for the five products with most units in stock SELECT TOP 5 productname, unitsinstock, unitsonorder FROM Products ORDER BY unitsinstock DESC Top with dates - Look for the five more recently hired employees SELECT TOP 5 lastname, firstname, DateofHire FROM SalesReps ORDER BY DateofHire DESC Get the ten largest orders for a particular product SELECT TOP 10 orderid, productid, (unitprice*quantity) AS orderamount FROM ProductsOrders WHERE (productid=2) ORDER BY (unitprice*quantity) DESC;
6
Chapter 15 – Calculated Fields Calculated fields are temporary columns created using arithmetic operators such as (+, *, -, /, ^) Are used extensively for short term or permanent changes with update statements. For example, a temporary price increase or cut in our web based product catalog. Business TaskTechnical Solution Create a product catalog with updated prices on the fly SELECT productname, productunitprice + 5 AS productprice FROM Products Calculate product inventory quantitiesSELECT productname, unitsinstock, unitsonorder, (unitsinstock + unitsonorder) AS TotalUnits FROM products Provide customers with different discounts based on the product supplier SELECT productname, SWITCH( SupplierID = 1, ProductUnitPrice*(1-0.2), SupplierID = 2, ProductUnitPrice*(1-0.15), SupplierID = 3, ProductUnitPrice*(1-0.18), SupplierID = 4, ProductUnitPrice*(1-0.25), TRUE, ProductUnitPrice*(1-0.1) ) AS ProductPrice FROM Products
7
Chapter 16 – Concatenated Fields Concatenating columns means nothing more than displaying the contents of two or more columns in one. To concatenate fields in MS Access 2010, we can use the "&" character or the "+" character. Business TaskTechnical Solution Put all customer address information in one field with spaces between values SELECT (address +' '+ city +' '+ state +' '+ zip) AS FullAddress FROM Customers Write a customer letterSELECT "Dear" + ' '+ (lastname + ' ' + firstname) +"." + ' '+ "It is our pleasure to announce that we reviewed your resume, and we have set up an interview time for you. Can you please verify that your address is" + ' ' + (address +' '+ City +' '+ State +' '+ Zip) + ' ' + "to send you corporate policy details and directions?" AS CustomerLetter FROM Customers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.