Wednesday, April 4, 2018

First Selects

Use Community_Assist;

Select PersonLastName, PersonFirstName
From Person;

Select * From Person

Select PersonLastName as [last Name], 
PersonFirstName as [First Name]
From Person;

Select PersonLastName, PersonFirstName
From Person
order by PersonLastName, PersonfirstName;

Select PersonLastName, PersonFirstName
From Person
order by PersonLastName Desc, PersonfirstName asc;

Select PersonLastName, PersonFirstName
From Person
where PersonLastName='Eliot'
order by PersonfirstName asc;

Select * from Donation
Where DonationAmount > 1000

Select * from Donation
Where DonationAmount <= 100

-- >, <, =, <=, >=, !=
Select  PersonKey, Donationamount from Donation
Order by PersonKey

Select Distinct PersonKey from Donation
Order by PersonKey

Select * from Donation where DonationDate>'9/5/15' 
and DonationDate <'9/6/15'

Select * from Donation where DonationDate between'9/5/15' 
and '9/6/15'

Select * from Person 
where PersonLastName like 'd_n%'

Select * from PersonAddress

Select * from PersonAddress where PersonAddressApt is not null
Select * from PersonAddress where PersonAddressApt is null
Select * from PersonAddress where Not PersonAddressCity='Seattle'

Top 10 and Offset

Use Community_Assist;

--top 10
Select top 10 donationDate, DonationAmount
From Donation
order by DonationAmount desc

--offset
Select donationDate, DonationAmount
From Donation
order by DonationAmount desc
offset 10 rows fetch next 5 rows only

No comments:

Post a Comment