Laboratoriya mashg’ulotlarida berilgan topshiriqlar Создание таблиц


Download 416.23 Kb.
bet19/21
Sana19.08.2023
Hajmi416.23 Kb.
#1668308
1   ...   13   14   15   16   17   18   19   20   21
Bog'liq
SQL command 29-11-2021 (5)

13 - LABORATORIYA ISHI
Mavzu: Murakkab so‘rovlar yaratish. TOP, LIMIT yoki ROWNUM

Ishdan maqsad: Berilgan predmet soha ma`lumotlar bazasidan foydalanib TOP, LIMIT yoki ROWNUM lardan foydalanishni o`rganish.
Masalani qo`yilishi: Predmet soha ma`lumotlar bazasi shakllantirilgandan so`ng undan unumli foydalanishni tashkil etish maqsadida TOP, LIMIT yoki ROWNUM lar orqali so`rovlar yaratish.
Uslubiy ko`rsatmalar: SQL LIMIT va SQL TOP operatorlarining vazifasi belgilangan satrlarni chaqirishdan iborat. SQL TOP operatori MS SQL Serverda ishlaydi, SQL LIMIT operatori esa MySQLda va Oracle da ROWNUM operatori ishlaydi ularnig vazifasi bir hil.

SQL Server / MS Access Syntax:
SELECT TOP number|percent column_name(s)
FROM table_name
WHERE condition;
MySQL Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;
Oracle Syntax:
SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;
Misol. MS SQL Serverda ishlash
SELECT TOP 3 * FROM Customers;
Misol. SQL da ishlash
SELECT * FROM Customers
LIMIT 3;
Misol. Oracleda ishlash
SELECT * FROM Customers
WHERE ROWNUM <= 3;
SQL TOP, LIMIT and FETCH FIRST Examples
The following SQL statement selects the first three records from the "Customers" table (for SQL Server/MS Access):
Example
SELECT TOP 3 * FROM Customers;

SELECT * FROM Customers


LIMIT 3;

SELECT * FROM Customers


FETCH FIRST 3 ROWS ONLY;

SQL TOP PERCENT Example


The following SQL statement selects the first 50% of the records from the "Customers" table (for SQL Server/MS Access):

SELECT TOP 50 PERCENT * FROM Customers;


ADD a WHERE CLAUSE


The following SQL statement selects the first three records from the "Customers" table, where the country is "Germany" (for SQL Server/MS Access):

SELECT TOP 3 * FROM Customers


WHERE Country='Germany';

SELECT * FROM Customers


WHERE Country='Germany'
LIMIT 3;

Example
SELECT * FROM Customers


WHERE Country='Germany'
FETCH FIRST 3 ROWS ONLY;

Download 416.23 Kb.

Do'stlaringiz bilan baham:
1   ...   13   14   15   16   17   18   19   20   21




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling