Begränsa data

Introduktion till Oracle SQL

Sara Billen

Curriculum Manager

Filtrera rader

Filter

 

  • Jämförelseoperatorer
  • Jämförelsenyckelord
  • Logiska operatorer
Introduktion till Oracle SQL

WHERE

SELECT FirstName, LastName, Country 
FROM Customer
WHERE Country = 'Portugal'
| FirstName | LastName  | Country  |
|-----------|-----------|----------|
| João      | Fernandes | Portugal |
| Madalena  | Sampaio   | Portugal |
Introduktion till Oracle SQL

Jämförelseoperatorer

Operator Beskrivning
> Större än
>= Större än eller lika med
< Mindre än
<= Mindre än eller lika med
= Lika med
<> Inte lika med
SELECT UnitPrice
FROM Track
WHERE UnitPrice <> 0.99
Introduktion till Oracle SQL

Jämförelsenyckelord

  Ytterligare WHERE-satsfunktioner

Introduktion till Oracle SQL

Jämförelsenyckelord – BETWEEN

SELECT Name, Milliseconds 
FROM Track
WHERE Milliseconds BETWEEN 100000 AND 200000
| Name              | Milliseconds |
|-------------------|--------------|
| Perfect           | 188133       |
| Right Through You | 176117       |
| We Die Young      | 152084       |
| Put You Down      | 196231       |
| ...                              |
Introduktion till Oracle SQL

Jämförelsenyckelord – IN

SELECT EmployeeId, LastName, Title
FROM Employee
WHERE EmployeeId IN (4, 5, 6)
| EmployeeId | LastName | Title               |
|------------|----------|---------------------|
| 4          | Park     | Sales Support Agent |
| 5          | Johnson  | Sales Support Agent |
| 6          | Mitchell | IT Manager          |
Introduktion till Oracle SQL

Jämförelsenyckelord – LIKE

Välj rader som matchar ett teckenmönster med LIKE

 

Symbol Beskrivning
% Representerar en sekvens av noll eller fler tecken
_ Representerar ett enskilt tecken
Introduktion till Oracle SQL

Jämförelsenyckelord – LIKE

SELECT LastName
FROM Employee
WHERE LastName LIKE '_a%'
| LastName |
|----------|
| Park     |
| Callahan |
Introduktion till Oracle SQL

Logiska operatorer

  Logiska operatorer

Introduktion till Oracle SQL

Logiska operatorer – AND

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      AND Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 66        | Australia      | 5.94  |
| 250       | Australia      | 13.86 |
| 305       | Australia      | 8.91  |
Introduktion till Oracle SQL

Logiska operatorer – OR

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      OR Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 3         | Belgium        | 5.94  |
| 4         | Canada         | 8.91  |
| 5         | USA            | 13.86 |
| 10        | Ireland        | 5.94  |
| ...                                |
Introduktion till Oracle SQL

Logiska operatorer – NOT

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry NOT IN ('Australia', 'Canada', 'United Kingdom')
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 1         | Germany        | 1.98  |
| 2         | Norway         | 3.96  |
| 3         | Belgium        | 5.94  |
| 5         | USA            | 13.86 |
| ...                                |
Introduktion till Oracle SQL

Sammanfattning

WHERE: filtrera rader baserat på ett villkor

  • Jämförelseoperatorer: =, <, >, <=, >=, <>
  • Jämförelsenyckelord: BETWEEN, IN, LIKE
  • Logiska operatorer: AND, OR, NOT
Introduktion till Oracle SQL

Nu kör vi en övning!

Introduktion till Oracle SQL

Preparing Video For Download...