mirror of
https://github.com/FlyInTheBox/31TSAI.git
synced 2024-11-09 20:44:11 +01:00
a
This commit is contained in:
parent
176e6a842e
commit
62daaa2254
2 changed files with 214 additions and 29 deletions
189
ProjektowanieBazDanych/_KL5D2.sql
Normal file
189
ProjektowanieBazDanych/_KL5D2.sql
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
SELECT ord.id AS 'ID',
|
||||||
|
customer.name AS 'KLIENT',
|
||||||
|
ord.date_ordered AS 'DATA',
|
||||||
|
emp.last_name AS 'SPRZEDAWCA',
|
||||||
|
ord.total AS 'WARTOŚĆ'
|
||||||
|
FROM ord, customer, emp
|
||||||
|
WHERE customer_id = ord.customer_id
|
||||||
|
AND emp.id = ord.sales_rep_id
|
||||||
|
AND (ord.total < 100 OR ord.total >= 1000);
|
||||||
|
|
||||||
|
SELECT ord.id AS 'ID',
|
||||||
|
customer.name AS 'KLIENT',
|
||||||
|
ord.date_ordered AS 'DATA',
|
||||||
|
emp.last_name AS 'SPRZEDAWCA',
|
||||||
|
ord.total AS 'WARTOŚĆ'
|
||||||
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
|
INNER JOIN emp ON emp.id = ord.sales_rep_id
|
||||||
|
WHERE (ord.total < 100 OR ord.total >= 1000);
|
||||||
|
|
||||||
|
|
||||||
|
SELECT ord.id AS 'ID',
|
||||||
|
customer.name AS 'KLIENT',
|
||||||
|
ord.date_ordered AS 'DATA',
|
||||||
|
emp.last_name AS 'SPRZEDAWCA',
|
||||||
|
ord.total AS 'WARTOŚĆ',
|
||||||
|
item.item_id AS 'LP',
|
||||||
|
product.name AS 'PRODUKT',
|
||||||
|
item.quantity AS 'ILOŚĆ',
|
||||||
|
item.price AS 'CENA'
|
||||||
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
|
INNER JOIN emp ON emp.id = ord.sales_rep_id
|
||||||
|
INNER JOIN item ON item.ord_id = ord.id
|
||||||
|
INNER JOIN product ON product.id = item.product_id
|
||||||
|
WHERE (ord.total < 100 OR ord.total >= 1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT ord.id,
|
||||||
|
customer.name,
|
||||||
|
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d, %W') AS 'data',
|
||||||
|
emp.last_name,
|
||||||
|
ord.total ,
|
||||||
|
item.item_id ,
|
||||||
|
product.name AS 'prod',
|
||||||
|
item.quantity,
|
||||||
|
item.price
|
||||||
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
|
INNER JOIN emp ON emp.id = ord.sales_rep_id
|
||||||
|
INNER JOIN item ON item.ord_id = ord.id
|
||||||
|
INNER JOIN product ON product.id = item.product_id
|
||||||
|
WHERE (ord.total < 100 OR ord.total >= 1000);
|
||||||
|
|
||||||
|
|
||||||
|
SELECT osoby.id,
|
||||||
|
osoby.nazwisko,
|
||||||
|
osoby.imie,
|
||||||
|
adresy.ulica,
|
||||||
|
adresy.miasto,
|
||||||
|
adresy.kod_pocz
|
||||||
|
FROM osoby LEFT OUTER JOIN adresy ON osoby.id = adresy.osoby_id;
|
||||||
|
|
||||||
|
SELECT ord.id,
|
||||||
|
customer.name,
|
||||||
|
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d, %W') AS 'data',
|
||||||
|
CONCAT(emp.last_name, ' ', emp.first_name) AS 'sprzed',
|
||||||
|
ord.total ,
|
||||||
|
IFNULL(item.item_id, 'B.D.') AS 'id',
|
||||||
|
IFNULL(product.name, 'Brak danych') AS 'prod',
|
||||||
|
IFNULL(item.quantity, '-----') AS 'ilosc',
|
||||||
|
IFNULL(item.price, '-----') AS 'cena'
|
||||||
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
|
INNER JOIN emp ON emp.id = ord.sales_rep_id
|
||||||
|
LEFT OUTER JOIN item ON item.ord_id = ord.id
|
||||||
|
LEFT OUTER JOIN product ON product.id = item.product_id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ZROBIĆ WIELE DO WIELU !!!!
|
||||||
|
|
||||||
|
|
||||||
|
SELECT osoby.id,
|
||||||
|
osoby.nazwisko,
|
||||||
|
osoby.imie,
|
||||||
|
adresy.ulica,
|
||||||
|
adresy.miasto,
|
||||||
|
adresy.kod_pocz
|
||||||
|
FROM osoby LEFT OUTER JOIN adresy ON osoby.id = adresy.osoby_id;
|
||||||
|
SELECT osoby.id,
|
||||||
|
osoby.nazwisko,
|
||||||
|
osoby.imie,
|
||||||
|
adresy.ulica,
|
||||||
|
adresy.miasto,
|
||||||
|
adresy.kod_pocz
|
||||||
|
FROM osoby RIGHT OUTER JOIN adresy ON osoby.id = adresy.osoby_id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT prac.id AS 'ID',
|
||||||
|
prac.last_name AS 'Nazwisko',
|
||||||
|
prac.first_name AS 'Imię',
|
||||||
|
prac.title AS 'Stanowisko',
|
||||||
|
prac.manager_id AS 'Szef',
|
||||||
|
szef.last_name AS 'N.SZEFA',
|
||||||
|
szef.title AS 'St.Szefa'
|
||||||
|
FROM emp AS szef, emp AS prac
|
||||||
|
WHERE szef.id = prac.manager_id;
|
||||||
|
|
||||||
|
SELECT prac.id AS 'ID',
|
||||||
|
prac.last_name AS 'Nazwisko',
|
||||||
|
prac.first_name AS 'Imię',
|
||||||
|
prac.title AS 'Stanowisko',
|
||||||
|
prac.manager_id AS 'Szef',
|
||||||
|
szef.last_name AS 'N.SZEFA',
|
||||||
|
szef.title AS 'St.Szefa'
|
||||||
|
FROM emp AS szef INNER JOIN emp AS prac ON szef.id = prac.manager_id;
|
||||||
|
|
||||||
|
|
||||||
|
SELECT prac.id AS 'ID',
|
||||||
|
prac.last_name AS 'Nazwisko',
|
||||||
|
prac.first_name AS 'Imię',
|
||||||
|
prac.title AS 'Stanowisko',
|
||||||
|
prac.manager_id AS 'Szef',
|
||||||
|
szef.last_name AS 'N.SZEFA',
|
||||||
|
szef.title AS 'St.Szefa'
|
||||||
|
FROM emp AS prac LEFT OUTER JOIN emp AS szef ON szef.id = prac.manager_id;
|
||||||
|
|
||||||
|
|
||||||
|
SELECT ord.id,
|
||||||
|
customer.name,
|
||||||
|
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d, %W') AS 'data',
|
||||||
|
CONCAT(prac.last_name, ' ', prac.first_name) AS 'sprzed',
|
||||||
|
CONCAT(szef.last_name, ' ', szef.first_name) AS 'szef',
|
||||||
|
ord.total,
|
||||||
|
IFNULL(item.item_id, 'B.D.') AS 'id',
|
||||||
|
IFNULL(product.name, 'Brak danych') AS 'prod',
|
||||||
|
IFNULL(item.quantity, '-----') AS 'ilosc',
|
||||||
|
IFNULL(item.price, '-----') AS 'cena'
|
||||||
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
|
INNER JOIN emp AS prac ON prac.id = ord.sales_rep_id
|
||||||
|
INNER JOIN emp AS szef ON szef.id = prac.manager_id
|
||||||
|
LEFT OUTER JOIN item ON item.ord_id = ord.id
|
||||||
|
LEFT OUTER JOIN product ON product.id = item.product_id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT emp.id,
|
||||||
|
emp.last_name,
|
||||||
|
emp.first_name,
|
||||||
|
emp.title,
|
||||||
|
emp.salary,
|
||||||
|
job.name,
|
||||||
|
job.salary_min,
|
||||||
|
job.salary_max
|
||||||
|
FROM emp, job
|
||||||
|
WHERE emp.title = job.name
|
||||||
|
AND(emp.salary >= job.salary_min AND emp.salary <= job.salary_max)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT emp.id,
|
||||||
|
emp.last_name,
|
||||||
|
emp.first_name,
|
||||||
|
emp.title,
|
||||||
|
emp.salary,
|
||||||
|
job.name,
|
||||||
|
job.salary_min,
|
||||||
|
job.salary_max
|
||||||
|
FROM emp, job
|
||||||
|
WHERE emp.title = job.name
|
||||||
|
AND (emp.salary < job.salary_min OR emp.salary > job.salary_max)
|
||||||
|
|
||||||
|
|
||||||
|
SELECT emp.id,
|
||||||
|
emp.last_name,
|
||||||
|
emp.first_name,
|
||||||
|
emp.title,
|
||||||
|
emp.salary,
|
||||||
|
job.name,
|
||||||
|
job.salary_min,
|
||||||
|
job.salary_max
|
||||||
|
FROM emp, job
|
||||||
|
WHERE emp.salary >= job.salary_min AND emp.salary <= job.salary_max
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,21 @@
|
||||||
<h2 align="center">Baza danych Wylazowski, Klasa 5D2</h2>
|
<h2 align="center">Baza danych Wylazowski, Klasa 5D2</h2>
|
||||||
<?php
|
<?php
|
||||||
$id_conn = mysqli_connect('localhost', 'root', '', 'baza_testowa');
|
$id_conn = mysqli_connect('localhost', 'root', '', 'baza_testowa');
|
||||||
$zapytanie = "SELECT ord.id,
|
$zapytanie = "SELECT ord.id,
|
||||||
customer.name,
|
customer.name,
|
||||||
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d') as date_ordered,
|
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d, %W') AS 'data',
|
||||||
DATE_FORMAT(ord.date_shipped,'%Y-%m-%d') as date_shipped,
|
CONCAT(emp.last_name, ' ', emp.first_name) AS 'sprzed',
|
||||||
CONCAT(emp.first_name,' ',emp.last_name) as sprzedawca,
|
CONCAT(szef.last_name, ' ', szef.first_name) AS 'szef',
|
||||||
ord.total,
|
ord.total,
|
||||||
ord.payment_type,
|
IFNULL(item.item_id, 'B.D.') AS 'id',
|
||||||
ord.order_filled,
|
IFNULL(product.name, 'Brak danych') AS 'prod',
|
||||||
product.name as nazwaProduktu,
|
IFNULL(item.quantity, '-----') AS 'ilosc',
|
||||||
item.price,
|
IFNULL(item.price, '-----') AS 'cena'
|
||||||
item.quantity
|
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
|
||||||
FROM ord join customer on customer.id=ord.customer_id
|
INNER JOIN emp ON emp.id = ord.sales_rep_id
|
||||||
join emp on ord.sales_rep_id=emp.id
|
JOIN emp as szef ON szef.id = emp.manager_id
|
||||||
join item on ord.id = item.ord_id
|
LEFT OUTER JOIN item ON item.ord_id = ord.id
|
||||||
join product on product.id = item.product_id
|
LEFT OUTER JOIN product ON product.id = item.product_id;";
|
||||||
WHERE ord.id >= 100;";
|
|
||||||
$wynik = mysqli_query($id_conn, $zapytanie);
|
$wynik = mysqli_query($id_conn, $zapytanie);
|
||||||
?>
|
?>
|
||||||
<table cellspacing="0" cellpadding="0" border="1" style="width: 90%;" align="center">
|
<table cellspacing="0" cellpadding="0" border="1" style="width: 90%;" align="center">
|
||||||
|
@ -35,14 +34,13 @@ $wynik = mysqli_query($id_conn, $zapytanie);
|
||||||
<td>ID</td>
|
<td>ID</td>
|
||||||
<td>Nazwa Klienta</td>
|
<td>Nazwa Klienta</td>
|
||||||
<td>Data zamówienia</td>
|
<td>Data zamówienia</td>
|
||||||
<td>Data dostarczenia</td>
|
|
||||||
<td>Sprzedawca</td>
|
<td>Sprzedawca</td>
|
||||||
|
<td>Szef</td>
|
||||||
<td>Wartość</td>
|
<td>Wartość</td>
|
||||||
<td>Typ płatności</td>
|
<td>ID</td>
|
||||||
<td>Status</td>
|
|
||||||
<td>Nazwa produktu</td>
|
<td>Nazwa produktu</td>
|
||||||
<td>Cena</td>
|
|
||||||
<td>Ilość</td>
|
<td>Ilość</td>
|
||||||
|
<td>Cena</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
while ($row = mysqli_fetch_array($wynik)) {
|
while ($row = mysqli_fetch_array($wynik)) {
|
||||||
|
@ -51,23 +49,21 @@ $wynik = mysqli_query($id_conn, $zapytanie);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['name']);
|
printf("%s", $row['name']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['date_ordered']);
|
printf("%s", $row['data']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['date_shipped']);
|
printf("%s", $row['sprzed']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['sprzedawca']);
|
printf("%s", $row['szef']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['total']);
|
printf("%s", $row['total']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['payment_type']);
|
printf("%s", $row['id']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['order_filled']);
|
printf("%s", $row['prod']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['nazwaProduktu']);
|
printf("%s", $row['ilosc']);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
printf("%s", $row['price']);
|
printf("%s", $row['cena']);
|
||||||
echo '</td><td>';
|
|
||||||
printf("%s", $row['quantity']);
|
|
||||||
echo '</td></tr>';
|
echo '</td></tr>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue