Telechargé par youcef hedibel

Tutorial SQLServer 12

publicité
‫‪SELECT‬‬
‫‪SQL‬‬
‫‪‬‬
‫‪‬‬
‫‪1‬‬
‫يقصد بالفرز ( ‪ ) Sort‬إعادة ترتيب السجالث تبعاً لمحتوياث حقل معين ترتيباً تصاعدياً أو تنازلياً ‪.‬‬
‫يقصد بالتصفيت ( ‪ ) Filter‬عرض السجالث التي تتطابق مع شرط معين‪.‬‬
‫‪Sort Type‬‬
Ascending
varchar char
smalldatetime
datetime



False
bit
RealEstate1
ORDER BY
SQL Server Management Studio
SQL
SELECT What FROM WhatObject ORDER BY WhatField;
LastName

SELECT FirstName,
LastName,
Gender,
ParentsNames,
SPHome
FROM Students
ORDER BY LastName;
GO
SELECT FirstName, LastName, Gender, EmailAddress
FROM Students
ORDER BY Gender;
GO
LastName
SELECT * FROM Students
ORDER BY LastName;
GO
ASC
SELECT * FROM Students
ORDER BY LastName ASC;
GO
DESC
SELECT FirstName,
LastName,
Gender,
ParentsNames,
SPHome
FROM Students
ORDER BY LastName DESC;
GO
1
SELECT house.YearBuilt AS [Year Built],
house.PropertyType AS [Type],
house.Bedrooms AS [Beds],
house.Bathrooms AS [Baths],
house.MarketValue AS [Value]
FROM Properties house
ORDER BY house.MarketValue
GO
F5
2
3
SELECT house.YearBuilt AS [Year Built],
house.PropertyType AS [Type],
house.Bedrooms AS [Beds],
house.Bathrooms AS [Baths],
house.MarketValue AS [Value]
FROM Properties house
ORDER BY YearBuilt DESC
GO
F5
4
SELECT
1993 31 12
1993
WHERE
WHERE
SELECT
SELECT What FROM WhatObject WHERE Expression;
ColumnName=Value
=
ColumnName
Value
SELECT DateOfBirth, LastName, FirstName,
Gender, State, ParentsNames
FROM Students
WHERE Gender='Female';
GO
ORDER BY
SELECT DateOfBirth, LastName, FirstName,
Gender, State, ParentsNames
FROM Students
WHERE State='MD'
ORDER BY LastName;
GO
WHERE
WHERE
1
SELECT house.PropertyNumber AS [Prop #],
house.Address,
house.City,
house.State,
house.ZIPCode AS [Location],
house.YearBuilt AS [Year Built],
house.PropertyType AS [Type],
house.MarketValue AS [Value]
FROM Properties house
WHERE house.ZIPCode < 20500
GO
F5
2
3
SELECT house.PropertyNumber AS [Prop #],
house.Address,
house.City,
house.State,
house.ZIPCode AS [Location],
house.YearBuilt AS [Year Built],
house.PropertyType AS [Type],
house.MarketValue AS [Value]
FROM Properties house
WHERE house.State = 'va'
GO
F5
2000
4
5
SELECT house.Address,
house.City,
house.State,
house.YearBuilt AS [Year Built],
house.PropertyType AS [Type],
house.MarketValue AS [Value]
FROM Properties house
WHERE house.YearBuilt >= 2000
GO
F5
6
7
SELECT house.PropertyType AS Type,
house.YearBuilt AS [Year Built],
house.City,
house.ZIPCode,
house.Bedrooms AS Beds,
house.Bathrooms AS Baths,
house.MarketValue AS Value
FROM Properties house
WHERE house.State = 'md'
ORDER BY house.ZIPCode
GO
F5
8
NOT
NOT
SELECT DateOfBirth, LastName, FirstName,
Gender, State, ParentsNames
FROM Students
WHERE NOT (Gender = 'Female');
GO
SELECT DateOfBirth, LastName, FirstName,
State, ParentsNames
FROM
Students
WHERE State IS NOT NULL;
GO
1
PropertyNumber
SELECT dbo.Properties.PropertyNumber AS [Prop #],
dbo.Properties.PropertyType AS Type,
dbo.Properties.YearBuilt AS [Year Built],
dbo.Properties.City,
dbo.Properties.State,
dbo.Properties.ZIPCode AS [ZIP Code],
dbo.Properties.Bedrooms AS Beds,
dbo.Properties.Bathrooms AS Baths,
dbo.Properties.MarketValue AS Value
FROM dbo.Properties
WHERE dbo.Properties.PropertyNumber IS NOT NULL
GO
F5
Téléchargement