SQL SYNTAX

Example of SQL using Special Operators And Build-in Function Item itemcode I001 I002 I003 I004 I005 I006 name Executive Table Table 5” <NULL> Printer LaserJet 1100 Printer LaserJet 1200 Mineral Water price 200 150 50 250 300 2 UOM PCS PCS PCS PCS PCS Carton qty 10 30 100 50 10 10

Special Operator 1) BETWEEN Q : List out all item code and name of those with the price between 180 to 310. SELECT * FROM Item WHERE price between 180 AND 310; I001 Executive Table 200 PCS I004 Printer LaserJet 1100 250 PCS I005 Printer LaserJet 1200 300 PCS 2) IS NULL Q : List out itemcode which does not have a item name. SELECT itemcode FROM Item WHERE name is null; I003 10 50 10

SELECT * FROM Item WHERE name LIKE ‘Printer%’.’I005’). SELECT name FROM Item WHERE name EXISTS. Printer LaserJet 1100 Printer LaserJet 1200 5) EXISTS Q : List out all the name of item where it is not null. itemcode name price I001 Executive Table 200 I002 Table 5” 150 I003 <NULL> 50 I004 Printer LaserJet 1100 250 I005 Printer LaserJet 1200 300 I006 Mineral Water 2 UOM PC PC PC PC PC Carton qty 10 30 100 50 10 10 50 10 . OR SELECT name FROM Item WHERE name IS NOT NULL.3) LIKE Q : List out all item information where its name consist printer character. Executive Table Table 5” Printer LaserJet 1100 Printer LaserJet 1200 Mineral Water UPDATE Q : change all the UOM with the values of PCS into PC UPDATE Item SET UOM=’PC’ WHERE UOM=’PCS’. OR SELECT name FROM Item WHERE itemcode=’I004’ OR itemcode=’I005’. I004 Printer LaserJet 1100 250 PCS I005 Printer LaserJet 1200 300 PCS 4) IN Q : List out the name of item where its itemcode is either I004 or I005 SELECT name FROM Item WHERE itemcode IN (‘I004’.

2 MAX SELECT MAX(Price) FROM Item. Printer LaserJet 1100 Printer LaserJet 1200 DISTINCT Q : list out all the available type of UOM SELECT DISTINCT UOM FROM Item. 158. PCS Carton Build-in function COUNT Q: List out the number of UOM associated with each UOM. 2 MIN SELECT MIN(Price) FROM Item.ORDER BY Q : list all the item information in an order sort by price SELECT * FROM Item ORDER BY price. SELECT COUNT(DISTINCT UOM) FROM Item.667 . itemcode name I006 Mineral Water I003 <NULL> I002 Table 5” I001 Executive Table I004 Printer LaserJet 1100 I005 Printer LaserJet 1200 price 2 50 150 200 250 300 UOM Carton PC PC PC PC PC qty 10 100 30 10 50 10 Q : list the name of the item in alphabetical order who have price more than 200 SELECT name FROM Item WHERE price >200 ORDER BY name. 300 AVG SELECT AVG(Price) FROM Item.

PCS Carton 5 1 . 952 GROUP BY SELECT UOM. COUNT(*) FROM Item GROUP BY UOM.SUM SELECT SUM(Price) FROM Item.

Sign up to vote on this title
UsefulNot useful