· 6 years ago · Mar 30, 2019, 12:58 PM
1--zad25
2drop table if exists os1
3drop table if exists os2
4drop table if exists os3
5go
6create table os1 (
7lp int primary key identity,
8data date,
9nazwisko varchar(50) not null
10)
11insert into os1 values
12('1998-09-01','Kowalski'),
13('1991-10-09','Malinowska'),
14('2001-02-09','Nowak'),
15('2002-03-12','Kowalewski');
16create table os2(
17lp int primary key identity,
18nazwisko varchar(50) not null,
19miasto varchar(50) not null
20)
21insert into os2 values
22('Kowalski','Sopot'),
23('Nowak','Gdańsk'),
24('Malinowska','Gdańsk'),
25('Kowalewski','Gdynia');
26create table os3(
27lp int primary key identity,
28nazwisko varchar(50) not null,
29brutto float not null
30)
31insert into os3 values
32('Kowalski',8120),
33('Malinowska',7891),
34('Nowak',9882),
35('Kowalewski',6789);
36go
37select*from os1
38select*from os2
39select*from os3
40go
41select os3.nazwisko,round((brutto/1.23),2) as netto,os3.brutto
42from os3 join os2
43on os3.nazwisko=os2.nazwisko
44where brutto>(select min(brutto) from os3 join os2 on os3.nazwisko=os2.nazwisko where miasto='Gdańsk')
45go
46select nazwisko,round((brutto/1.23),2) as netto,brutto
47from os3
48where brutto=(select max(brutto) from os3)
49go
50select miasto,round((avg(brutto)/1.23),2) as netto,round(avg(brutto),2)as brutto
51from os3 join os2
52on os3.nazwisko=os2.nazwisko
53group by miasto
54go
55--zad26
56drop table if exists os1
57drop table if exists os2
58drop table if exists os3
59go
60create table os1 (
61imie varchar(50) not null ,
62nazwisko varchar(50) not null primary key
63)
64insert into os1 values
65('Jan','Kowalski'),
66('Tomasz','Nowicki'),
67('Krzysztof','Malinowski'),
68('Irena','Malicka');
69create table os2(
70nazwisko varchar(50) not null primary key,
71wzrost float not null
72)
73insert into os2 values
74('Kowalski',190),
75('Malicka',195),
76('Malinowski',185),
77('Nowicki',188);
78create table os3(
79miasto varchar(50) not null ,
80nazwisko varchar(50) not null primary key,
81netto float not null
82)
83insert into os3 values
84('Gdańsk','Kowalski',2500.90),
85('Gdynia','Nowicki',4300.90),
86('Gdańsk','Malinowski',2700.90),
87('Gdynia','Malicka',3600.90);
88go
89select*from os1
90select*from os2
91select*from os3
92alter table os1 add data date
93go
94update os1 set data='1991-01-01' where nazwisko='Kowalski'
95update os1 set data='1994-01-10' where nazwisko='Nowicki'
96update os1 set data='1991-01-21' where nazwisko='Malinowski'
97update os1 set data='1986-09-21' where nazwisko='Malicka'
98select imie,nazwisko,convert(varchar,data,102)as data
99from os1
100go
101select year(data)as 'rok urodzenia', datediff(year,data,getdate())as wiek, os3.miasto,os1.nazwisko, os2.wzrost/100 as wzrost
102from os1 join os3
103on os1.nazwisko=os3.nazwisko
104join os2
105on os1.nazwisko=os2.nazwisko
106where miasto='Gdańsk'
107
108go
109select avg(wzrost)/100 as 'średni wzrost'
110from os2 join os3
111on os2.nazwisko=os3.nazwisko
112where os3.miasto='Gdańsk'
113go
114select count(os1.nazwisko) as 'ilość osób',miasto
115from os1 join os2
116on os1.nazwisko=os2.nazwisko
117join os3
118on os1.nazwisko=os3.nazwisko
119where year(data)>1990 and wzrost>(select avg(wzrost)
120from os2 join os3
121on os2.nazwisko=os3.nazwisko
122where os3.miasto='Gdańsk')
123group by miasto
124go