mirror of
https://github.com/FlyInTheBox/31TSAI.git
synced 2024-11-09 20:44:11 +01:00
Compare commits
2 commits
f1b201c121
...
62daaa2254
Author | SHA1 | Date | |
---|---|---|---|
62daaa2254 | |||
176e6a842e |
2 changed files with 214 additions and 28 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -13,19 +13,19 @@
|
|||
$id_conn = mysqli_connect('localhost', 'root', '', 'baza_testowa');
|
||||
$zapytanie = "SELECT ord.id,
|
||||
customer.name,
|
||||
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d') as date_ordered,
|
||||
DATE_FORMAT(ord.date_shipped,'%Y-%m-%d') as date_shipped,
|
||||
CONCAT(emp.first_name,' ',emp.last_name) as sprzedawca,
|
||||
DATE_FORMAT(ord.date_ordered,'%Y-%m-%d, %W') AS 'data',
|
||||
CONCAT(emp.last_name, ' ', emp.first_name) AS 'sprzed',
|
||||
CONCAT(szef.last_name, ' ', szef.first_name) AS 'szef',
|
||||
ord.total,
|
||||
ord.payment_type,
|
||||
ord.order_filled,
|
||||
product.name as nazwaProduktu,
|
||||
item.price,
|
||||
item.quantity
|
||||
FROM ord join customer on customer.id=ord.customer_id
|
||||
join emp on ord.sales_rep_id=emp.id
|
||||
join item on ord.id = item.ord_id
|
||||
join product on product.id = item.product_id WHERE ord.id >= 100;";
|
||||
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
|
||||
JOIN emp as szef ON szef.id = emp.manager_id
|
||||
LEFT OUTER JOIN item ON item.ord_id = ord.id
|
||||
LEFT OUTER JOIN product ON product.id = item.product_id;";
|
||||
$wynik = mysqli_query($id_conn, $zapytanie);
|
||||
?>
|
||||
<table cellspacing="0" cellpadding="0" border="1" style="width: 90%;" align="center">
|
||||
|
@ -34,14 +34,13 @@ $wynik = mysqli_query($id_conn, $zapytanie);
|
|||
<td>ID</td>
|
||||
<td>Nazwa Klienta</td>
|
||||
<td>Data zamówienia</td>
|
||||
<td>Data dostarczenia</td>
|
||||
<td>Sprzedawca</td>
|
||||
<td>Szef</td>
|
||||
<td>Wartość</td>
|
||||
<td>Typ płatności</td>
|
||||
<td>Status</td>
|
||||
<td>ID</td>
|
||||
<td>Nazwa produktu</td>
|
||||
<td>Cena</td>
|
||||
<td>Ilość</td>
|
||||
<td>Cena</td>
|
||||
</tr>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_array($wynik)) {
|
||||
|
@ -50,23 +49,21 @@ $wynik = mysqli_query($id_conn, $zapytanie);
|
|||
echo '</td><td>';
|
||||
printf("%s", $row['name']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['date_ordered']);
|
||||
printf("%s", $row['data']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['date_shipped']);
|
||||
printf("%s", $row['sprzed']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['sprzedawca']);
|
||||
printf("%s", $row['szef']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['total']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['payment_type']);
|
||||
printf("%s", $row['id']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['order_filled']);
|
||||
printf("%s", $row['prod']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['nazwaProduktu']);
|
||||
printf("%s", $row['ilosc']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['price']);
|
||||
echo '</td><td>';
|
||||
printf("%s", $row['quantity']);
|
||||
printf("%s", $row['cena']);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue