SlideShare a Scribd company logo
1 of 28
 Combining rules in a single WHERE clause
would be useful
 AND and OR allow us to do this
 NOT also allows us to modify rule behaviour
 When these are combined together, problems
in rule ordering can occur.
 This is solved using parentheses.
 AND combines rules together so that they ALL must be
true.
 Lets revisit the CAR table:
REGNO MAKE COLOUR PRICE OWNER
F611 AAA FORD RED 12000 Jim Smith
J111 BBB SKODA BLUE 11000 Jim Smith
A155 BDE MERCEDES BLUE 22000 Bob Smith
K555 GHT FIAT GREEN 6000 Bob Jones
SC04 BFE SMART BLUE 13000
SELECT regno from car SELECT regno from car
where colour = ‘BLUE’ WHERE regno LIKE ‘%5’
REGNO
J111 BBB
A155 BDE
SC04 BFE
REGNO
A155 BDE
K555 GHT
SELECT regno from car
WHERE colour = ‘BLUE’ and regno LIKE ‘%5%’
;
REGNO
A155 BDE
 You can have as many rules as you like
ANDed together.
 For example:
SELECT regno
FROM car
WHERE colour = ‘BLUE’
AND regno like ‘%5%’
AND owner like ‘Bob %’
;
 OR is like ‘either’. So long as one of the rules is true
then the filter is true.
 Looks for cars which are EITHER red or blue…
SELECT regno,colour from CAR
WHERE colour = ‘RED’ OR colour = ‘BLUE’
REGNO COLOUR
F611 AAA RED
J111 BBB BLUE
A155 BDE BLUE
SC04 BFE BLUE
 NOT inverts the rule it is put in front of:
 WHERE colour = ‘RED’
 This could be inverted as:
◦ WHERE colour != ‘RED’
◦ WHERE NOT colour = ‘RED’
 NOT is not really useful in this example, but
comes into its own in more complex rulesets.
 Precedence is the order in which the rules are evaluated and
combined together.
 It is NOT in the order they are written.
 Rules are combined together firstly at AND, then OR, and
finally at NOT.
 Consider : Car has a 5 in reg and is either red or blue.
SELECT regno,colour from car
WHERE colour = ‘RED’ -- Line 1
OR colour = ‘BLUE’ -- Line 2
AND regno LIKE ‘%5%’ -- Line 3
 Rewrite as:
SELECT regno,colour from car
WHERE (colour = ‘RED’
OR colour = ‘BLUE’ )
AND regno LIKE ‘%5%’
 Might be clearer as:
SELECT regno,colour from car
WHERE ( colour = ‘RED’ OR colour = ‘BLUE’ )
AND regno LIKE ‘%5%’
 Find all the colours used in cars.
SELECT colour from car;
COLOUR
RED
BLUE
BLUE
GREEN
BLUE
SELECT DISTINCT colour from car;
COLOUR
RED
BLUE
GREEN
 It would be nice to be able to order the output using a
sort.
 SELECT make from car;
MAKE
FORD
SKODA
MERCEDES
FIAT
SMART
 Sort by alphabetical or numeric order: ASC
 ORDER BY … ASC is the default.
SELECT make from car
ORDER BY make;
MAKE
FORD
FIAT
MERCEDES
SKODA
SMART
 Sort by reverse alphabetical or numeric order: DESC
 ORDER BY … DESC must be selected.
SELECT make from car
ORDER BY make DESC;
MAKE
SMART
SKODA
MERCEDES
FIAT
FORD
 ORDER BY can take multiple columns.
SELECT make,colour FROM car
ORDER BY colour,make;
MAKE COLOUR
SKODA BLUE
SMART BLUE
MERCEDES BLUE
FIAT GREEN
FORD RED
 When you have a list of OR, all on the same attribute, then IN
could be a simpler way:
 Rather Than:
SELECT regno,make FROM car
WHERE make = ‘SKODA’ or make = ‘SMART’
 Have
SELECT regno,make FROM car
WHERE make in (‘SKODA’,’SMART’);
 Aggregate functions allow you to write queries to produce
statistics on the data in the database.
 These functions are sometimes also called SET functions.
 These include:
◦ AVG (calculate the average)
◦ SUM
◦ MAX
◦ MIN
◦ COUNT
SELECT price FROM car;
SELECT avg(price) FROM car;
PRICE
12000
11000
22000
6000
13000
AVG(PRICE)
12800
 Add up all the values in a column
SELECT sum(price) FROM car;
SUM(PRICE)
64000
 What is the maximum value in a column
SELECT max(price) FROM car;
MAX(PRICE)
22000
 What is the minimum value in a column
SELECT min(price) FROM car;
MIN(PRICE)
6000
 How many rows make up a column
SELECT count(price) FROM car;
COUNT(PRICE)
5
• Count(*) is similar, but also counts when price is NULL.
SELECT count(*) FROM car;
 Sometimes you do not want to count how many
rows are in a column, but how many different
values could be found in that column.
 There is a special variant of count which does this:
SELECT count(colour) from car;
SELECT count(DISTINCT colour) from car;
COUNT(PRICE)
5
COUNT(PRICE)
3
 Aggregation functions so far have only been shown in queries
with only the single aggregation function on the select line.
 You can combine functions and non-functions on the select
line.
 To do this you need GROUP BY.
 Question: What is the most expensive car for each colour.
 Intuitively the following seems right, but will not execute!
SELECT colour,max(price)
FROM car;
SELECT colour,price
FROM car;
SELECT colour,max(price)
FROM car
GROUP BY colour;
COLOUR PRICE
RED 12000
BLUE 11000
BLUE 22000
GREEN 6000
BLUE 13000
COLOUR PRICE
RED 12000
BLUE 22000
GREEN 6000
 WHILE allows rules for each row.
 HAVING allows rules for each group of a GROUP BY.
 Consider the problem “Who has more than 1 car”.
 We would like to say:
SELECT owner from car where count(owner) > 1
 Aggregate functions are not allowed in WHERE.
 They are allowed in HAVING.
SELECT owner,count(regno)
FROM car
GROUP BY owner
HAVING count(regno) > 1
OR
SELECT owner
FROM car
GROUP BY owner
HAVING count(regno) > 1
count(*) works just as well in this case.

More Related Content

Viewers also liked

Czym jest cellulit?
Czym jest cellulit?Czym jest cellulit?
Czym jest cellulit?spontex
 
“La Ciencia y el Conocimiento Científico en Beneficio del Hombre
“La Ciencia y el Conocimiento Científico en Beneficio del Hombre“La Ciencia y el Conocimiento Científico en Beneficio del Hombre
“La Ciencia y el Conocimiento Científico en Beneficio del Hombrefabuitoj
 
Ciencia y tecnología
Ciencia y tecnologíaCiencia y tecnología
Ciencia y tecnologíadianafani
 
Entorno gráfico word
Entorno gráfico wordEntorno gráfico word
Entorno gráfico wordzanethpineda
 

Viewers also liked (9)

Oei dec-15
Oei dec-15Oei dec-15
Oei dec-15
 
Nutrients vs. Calories
Nutrients vs. CaloriesNutrients vs. Calories
Nutrients vs. Calories
 
Colusión
ColusiónColusión
Colusión
 
Czym jest cellulit?
Czym jest cellulit?Czym jest cellulit?
Czym jest cellulit?
 
Oei feb-16
Oei feb-16Oei feb-16
Oei feb-16
 
Informatica
InformaticaInformatica
Informatica
 
“La Ciencia y el Conocimiento Científico en Beneficio del Hombre
“La Ciencia y el Conocimiento Científico en Beneficio del Hombre“La Ciencia y el Conocimiento Científico en Beneficio del Hombre
“La Ciencia y el Conocimiento Científico en Beneficio del Hombre
 
Ciencia y tecnología
Ciencia y tecnologíaCiencia y tecnología
Ciencia y tecnología
 
Entorno gráfico word
Entorno gráfico wordEntorno gráfico word
Entorno gráfico word
 

Similar to http://boxinglatestnews.com

Data Management using tableau
Data Management using tableauData Management using tableau
Data Management using tableauKanika Nagpal
 
Cis1 pp group prject 6d. auto cars
Cis1 pp group prject 6d. auto carsCis1 pp group prject 6d. auto cars
Cis1 pp group prject 6d. auto carsAlizeScarborough
 
2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manualjdksmemd
 
2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manualjksemd dysjekmdm
 
CARVANA - Predicting the purchase quality in car
CARVANA - Predicting the  purchase quality in carCARVANA - Predicting the  purchase quality in car
CARVANA - Predicting the purchase quality in carShankarPrasaadRajama
 
Cis1-214-project6d-autocars
Cis1-214-project6d-autocarsCis1-214-project6d-autocars
Cis1-214-project6d-autocarsAlizeScarborough
 
Data Analytics Project Presentation
Data Analytics Project PresentationData Analytics Project Presentation
Data Analytics Project PresentationRohit Vaze
 
cars design code power system detai.pptx
cars design code power system detai.pptxcars design code power system detai.pptx
cars design code power system detai.pptxabomoayad19309
 
Las vegas8202016
Las vegas8202016Las vegas8202016
Las vegas8202016Carstir.com
 
Car Study & Statistics
Car Study & StatisticsCar Study & Statistics
Car Study & StatisticsMelissa Anne Lim
 
Orange county8172016
Orange county8172016Orange county8172016
Orange county8172016Carstir.com
 
San diego8202016
San diego8202016San diego8202016
San diego8202016Carstir.com
 
Jacksonville8182016
Jacksonville8182016Jacksonville8182016
Jacksonville8182016Carstir.com
 

Similar to http://boxinglatestnews.com (20)

Data Management using tableau
Data Management using tableauData Management using tableau
Data Management using tableau
 
SQL
SQLSQL
SQL
 
Cis1 pp group prject 6d. auto cars
Cis1 pp group prject 6d. auto carsCis1 pp group prject 6d. auto cars
Cis1 pp group prject 6d. auto cars
 
2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual
 
2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual2003 DODGE RAM TRUCK Service Repair Manual
2003 DODGE RAM TRUCK Service Repair Manual
 
CARVANA - Predicting the purchase quality in car
CARVANA - Predicting the  purchase quality in carCARVANA - Predicting the  purchase quality in car
CARVANA - Predicting the purchase quality in car
 
Cis1-214-project6d-autocars
Cis1-214-project6d-autocarsCis1-214-project6d-autocars
Cis1-214-project6d-autocars
 
Database Query Design
Database Query DesignDatabase Query Design
Database Query Design
 
Dallas8202016
Dallas8202016Dallas8202016
Dallas8202016
 
Data Analytics Project Presentation
Data Analytics Project PresentationData Analytics Project Presentation
Data Analytics Project Presentation
 
Sql1
Sql1Sql1
Sql1
 
Oracle
OracleOracle
Oracle
 
Dallas8182016
Dallas8182016Dallas8182016
Dallas8182016
 
cars design code power system detai.pptx
cars design code power system detai.pptxcars design code power system detai.pptx
cars design code power system detai.pptx
 
Las vegas8202016
Las vegas8202016Las vegas8202016
Las vegas8202016
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
Car Study & Statistics
Car Study & StatisticsCar Study & Statistics
Car Study & Statistics
 
Orange county8172016
Orange county8172016Orange county8172016
Orange county8172016
 
San diego8202016
San diego8202016San diego8202016
San diego8202016
 
Jacksonville8182016
Jacksonville8182016Jacksonville8182016
Jacksonville8182016
 

Recently uploaded

Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistKHM Anwar
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...sonatiwari757
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 

Recently uploaded (20)

Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization Specialist
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 

http://boxinglatestnews.com

  • 1.
  • 2.  Combining rules in a single WHERE clause would be useful  AND and OR allow us to do this  NOT also allows us to modify rule behaviour  When these are combined together, problems in rule ordering can occur.  This is solved using parentheses.
  • 3.  AND combines rules together so that they ALL must be true.  Lets revisit the CAR table: REGNO MAKE COLOUR PRICE OWNER F611 AAA FORD RED 12000 Jim Smith J111 BBB SKODA BLUE 11000 Jim Smith A155 BDE MERCEDES BLUE 22000 Bob Smith K555 GHT FIAT GREEN 6000 Bob Jones SC04 BFE SMART BLUE 13000
  • 4. SELECT regno from car SELECT regno from car where colour = ‘BLUE’ WHERE regno LIKE ‘%5’ REGNO J111 BBB A155 BDE SC04 BFE REGNO A155 BDE K555 GHT
  • 5. SELECT regno from car WHERE colour = ‘BLUE’ and regno LIKE ‘%5%’ ; REGNO A155 BDE
  • 6.  You can have as many rules as you like ANDed together.  For example: SELECT regno FROM car WHERE colour = ‘BLUE’ AND regno like ‘%5%’ AND owner like ‘Bob %’ ;
  • 7.  OR is like ‘either’. So long as one of the rules is true then the filter is true.  Looks for cars which are EITHER red or blue… SELECT regno,colour from CAR WHERE colour = ‘RED’ OR colour = ‘BLUE’ REGNO COLOUR F611 AAA RED J111 BBB BLUE A155 BDE BLUE SC04 BFE BLUE
  • 8.  NOT inverts the rule it is put in front of:  WHERE colour = ‘RED’  This could be inverted as: ◦ WHERE colour != ‘RED’ ◦ WHERE NOT colour = ‘RED’  NOT is not really useful in this example, but comes into its own in more complex rulesets.
  • 9.  Precedence is the order in which the rules are evaluated and combined together.  It is NOT in the order they are written.  Rules are combined together firstly at AND, then OR, and finally at NOT.  Consider : Car has a 5 in reg and is either red or blue. SELECT regno,colour from car WHERE colour = ‘RED’ -- Line 1 OR colour = ‘BLUE’ -- Line 2 AND regno LIKE ‘%5%’ -- Line 3
  • 10.  Rewrite as: SELECT regno,colour from car WHERE (colour = ‘RED’ OR colour = ‘BLUE’ ) AND regno LIKE ‘%5%’  Might be clearer as: SELECT regno,colour from car WHERE ( colour = ‘RED’ OR colour = ‘BLUE’ ) AND regno LIKE ‘%5%’
  • 11.  Find all the colours used in cars. SELECT colour from car; COLOUR RED BLUE BLUE GREEN BLUE
  • 12. SELECT DISTINCT colour from car; COLOUR RED BLUE GREEN
  • 13.  It would be nice to be able to order the output using a sort.  SELECT make from car; MAKE FORD SKODA MERCEDES FIAT SMART
  • 14.  Sort by alphabetical or numeric order: ASC  ORDER BY … ASC is the default. SELECT make from car ORDER BY make; MAKE FORD FIAT MERCEDES SKODA SMART
  • 15.  Sort by reverse alphabetical or numeric order: DESC  ORDER BY … DESC must be selected. SELECT make from car ORDER BY make DESC; MAKE SMART SKODA MERCEDES FIAT FORD
  • 16.  ORDER BY can take multiple columns. SELECT make,colour FROM car ORDER BY colour,make; MAKE COLOUR SKODA BLUE SMART BLUE MERCEDES BLUE FIAT GREEN FORD RED
  • 17.  When you have a list of OR, all on the same attribute, then IN could be a simpler way:  Rather Than: SELECT regno,make FROM car WHERE make = ‘SKODA’ or make = ‘SMART’  Have SELECT regno,make FROM car WHERE make in (‘SKODA’,’SMART’);
  • 18.  Aggregate functions allow you to write queries to produce statistics on the data in the database.  These functions are sometimes also called SET functions.  These include: ◦ AVG (calculate the average) ◦ SUM ◦ MAX ◦ MIN ◦ COUNT
  • 19. SELECT price FROM car; SELECT avg(price) FROM car; PRICE 12000 11000 22000 6000 13000 AVG(PRICE) 12800
  • 20.  Add up all the values in a column SELECT sum(price) FROM car; SUM(PRICE) 64000
  • 21.  What is the maximum value in a column SELECT max(price) FROM car; MAX(PRICE) 22000
  • 22.  What is the minimum value in a column SELECT min(price) FROM car; MIN(PRICE) 6000
  • 23.  How many rows make up a column SELECT count(price) FROM car; COUNT(PRICE) 5 • Count(*) is similar, but also counts when price is NULL. SELECT count(*) FROM car;
  • 24.  Sometimes you do not want to count how many rows are in a column, but how many different values could be found in that column.  There is a special variant of count which does this: SELECT count(colour) from car; SELECT count(DISTINCT colour) from car; COUNT(PRICE) 5 COUNT(PRICE) 3
  • 25.  Aggregation functions so far have only been shown in queries with only the single aggregation function on the select line.  You can combine functions and non-functions on the select line.  To do this you need GROUP BY.  Question: What is the most expensive car for each colour.  Intuitively the following seems right, but will not execute! SELECT colour,max(price) FROM car;
  • 26. SELECT colour,price FROM car; SELECT colour,max(price) FROM car GROUP BY colour; COLOUR PRICE RED 12000 BLUE 11000 BLUE 22000 GREEN 6000 BLUE 13000 COLOUR PRICE RED 12000 BLUE 22000 GREEN 6000
  • 27.  WHILE allows rules for each row.  HAVING allows rules for each group of a GROUP BY.  Consider the problem “Who has more than 1 car”.  We would like to say: SELECT owner from car where count(owner) > 1  Aggregate functions are not allowed in WHERE.  They are allowed in HAVING.
  • 28. SELECT owner,count(regno) FROM car GROUP BY owner HAVING count(regno) > 1 OR SELECT owner FROM car GROUP BY owner HAVING count(regno) > 1 count(*) works just as well in this case.