-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL(Introduction).sql
120 lines (95 loc) · 2.73 KB
/
SQL(Introduction).sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use Northwind
select ProductID ,
ProductName,
CategoryID
from Products
where ProductID =5
/*SQL server her türlü veriyi(bilgiyi ) düzenli bir şekilde depolayıp CREATE , DELETE , UPDATE , READ operasyonlarını yapabileceğimiz birden fazla kişiyle yetkilendirip çalışabileceğimiz bir veritabanıdır */
select GETDATE()
/* Temel sorgu "select * from -tablo ismi-" (select işlem başında yazılır * tüm tabloyu getirmek için from [den " dan ] o tablodan anlmaında kullanılır)*/
select * from Employees
/*tablo kolonlardan ve satırlardan oluşur ama biz bu kolonların isimlerini çağrı amacına göre değiştirebiliriz*/
select FirstName [isim] ,
LastName [Soyadı],
Title [Unvan]
from Employees
select (FirstName +' '+ LastName) as [full Name] from Employees
/*year metodunun içine getdate yazarak güncel tarihi elde etmiş olduk bu tarihi year (yıll cinsinden ) çalışnların doğum tarihinden çıkartırsak yaşları bulmuş oluruz */
select(FirstName +' '+LastName) as [Full Name] ,
BirthDate as [Doğum Yılı] ,
year(getdate()) - year(BirthDate) as [Yaş]
from Employees
/*Where : belirli bir kolondan bilgi getirir*/
select ProductID ,
ProductName
from Products
where ProductID = 5
select EmployeeID,
FirstName,
LastName,
BirthDate
from Employees
where BirthDate = 1966 /*Sor*/
/*and , ın ,or*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where EmployeeID in (1,2,3)
/*between*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where EmployeeID between 1 and 2
/*Like Karaterin ilgili kolonda olup olmadığını sorgular*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like '%a%'
/*Baş harf arama */
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like 'a%'
/*a yada b harfi ile başlayan*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like '[ab]%'
/*a ile başlayıp e ile biten*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like 'a%e'
/*a ile başlayıp 4 harfılı ismi olan*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like 'a___'
/*İikinci harfi n alan isimler*/
select EmployeeID,
FirstName,
LastName,
Title
from Employees
where FirstName like '_n%'
select DATEPART(YEAR,GETDATE()) as 'yıll'
select FirstName,
LastName,
Title,
BirthDate,
year(getdate()) - year(BirthDate) as [Yaş]
from Employees where Yaş = 73 /*Yaş Kırmızı hocaya sor*/