Skip to content

Commit 3b5a835

Browse files
committed
Lab2 instead of cw2, because of exercises on labs
1 parent 112655e commit 3b5a835

File tree

2 files changed

+135
-11
lines changed

2 files changed

+135
-11
lines changed

cw2.sql renamed to lab2.sql

Lines changed: 131 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
--totalny chaos zaraz po zmianie prowadzacego dlatego to ten .sql nie jest az tak zorganizowany sadge ;-(
2-
3-
4-
-- SKILL CHECK BY ZYGMUNT GAMING
1+
--
52
USE library
63
SELECT title
74
FROM title
@@ -185,7 +182,7 @@ SELECT (SELECT TOP 1 UnitPrice
185182

186183
-- 4. Wypisz informację o wszystkich produktach o cenie
187184
-- powyżej średniej
188-
--najpierw liczymy xddxdxdx
185+
--
189186

190187
SELECT AVG(UnitPrice)
191188
FROM Products;
@@ -224,7 +221,7 @@ GROUP BY OrderID;
224221
-- 3. Podaj liczbę zamówień dostarczanych przez
225222
-- poszczególnych spedytorów
226223

227-
SELECT ShipVia, COUNT(OrderId) as no_orders
224+
SELECT ShipVia, COUNT(*) as no_orders
228225
FROM Orders
229226
GROUP BY ShipVia
230227

@@ -240,10 +237,23 @@ ORDER BY no_orders DESC
240237
-- 1. Wyświetl zamówienia dla których liczba pozycji
241238
-- zamówienia jest większa niż 5
242239

243-
SELECT orderid, COUNT(orderid) as number
240+
241+
242+
243+
244+
245+
SELECT orderid, COUNT(*) as 'total orders'
244246
FROM [Order Details]
245247
GROUP BY orderid
246-
HAVING COUNT(OrderID)>5
248+
HAVING COUNT(*)>5
249+
250+
251+
252+
253+
254+
255+
256+
247257

248258
-- 2. Wyświetl klientów, dla których w 1998 roku zrealizowano
249259
-- więcej niż 8 zamówień (wyniki posortuj malejąco wg
@@ -259,11 +269,121 @@ GROUP BY CustomerID
259269
HAVING COUNT(Orders.OrderID)>8
260270
ORDER BY 'total sum' DESC;
261271

262-
-- ??
272+
-- apparently freight = oplata za przewoz XDDD
273+
-- freight z ang. = załadunek XDDDDD
263274

264-
SELECT Orders.CustomerID, COUNT(Orders.OrderID) as 'total orders'
265-
FROM Orders
275+
SELECT CustomerID, SUM((UnitPrice * Quantity * (1 - Discount))) as 'totalsum'
276+
FROM Orders, [Order Details]
266277
WHERE YEAR(ShippedDate)=1998
267278
GROUP BY CustomerID
268279
HAVING COUNT(Orders.OrderID)>8
280+
ORDER BY totalsum DESC;
281+
282+
283+
284+
285+
286+
287+
SELECT productid, orderid, sum(quantity)
288+
FROM orderhist
289+
GROUP BY productid, orderid WITH CUBE
290+
ORDER BY productid, orderid
291+
292+
293+
SELECT '<null>', '<null>',sum(quantity)
294+
FROM orderhist
295+
296+
297+
SELECT productid, sum(quantity)
298+
FROM orderhist
299+
WHERE ProductID=1 --2
300+
GROUP BY productid
301+
302+
303+
304+
--ZADANIE AGREGATY KONCOWE
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
SELECT FirstName + ' ' + LastName, DATEDIFF(year, HireDate, GETDATE())
316+
FROM Employees
317+
318+
319+
320+
321+
322+
SELECT MIN(LEN(FirstName))
323+
FROM Employees
324+
325+
326+
327+
328+
329+
330+
331+
332+
SELECT EmployeeID, COUNT(*), MIN(OrderDate)
333+
FROM Orders
334+
GROUP BY EmployeeID
335+
ORDER BY EmployeeID
336+
337+
338+
339+
340+
341+
342+
343+
344+
SELECT CustomerID, SUM(Freight)
345+
FROM Orders
346+
WHERE RequiredDate - ShippedDate < 0
347+
GROUP BY CustomerID
348+
349+
350+
351+
352+
353+
354+
USE Library
355+
SELECT TOP 1 YEAR(in_date),SUM(fine_assessed)
356+
FROM loanhist
357+
GROUP BY YEAR(in_date)
358+
ORDER BY SUM(fine_assessed) DESC;
359+
360+
361+
362+
363+
364+
365+
366+
367+
368+
369+
370+
371+
372+
373+
374+
375+
376+
377+
378+
379+
380+
381+
382+
383+
384+
385+
386+
387+
388+
269389

test.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
RESTORE DATABASE joindb
3+
FROM DISK = 'C:\Users\WLGS\Desktop\joindb2012.bak'
4+
WITH REPLACE

0 commit comments

Comments
 (0)