This commit is contained in:
FlyInTheBox 2023-11-06 14:32:58 +01:00
parent b25e7118a5
commit f5d1da0aa0
3 changed files with 361 additions and 26 deletions

View file

@ -0,0 +1,320 @@
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
SELECT osoby.id,
osoby.nazwisko,
osoby.imie,
osoby.pesel,
adresy.ulica,
adresy.kod_pocz,
adresy.miasto
FROM osoby INNER JOIN oso_adr ON osoby.id = oso_adr.osoby_id
INNER JOIN adresy ON adresy.id = oso_adr.adresy_id;
SELECT emp.last_name, <-błąd sensu
MAX(salary),
MIN(salary),
AVG(salary),
SUM(salary),
COUNT(salary)
FROM emp;
SELECT emp.last_name, <-błąd sensu
MAX(salary),
MIN(salary),
AVG(salary),
SUM(salary),
COUNT(salary)
FROM emp;
SELECT emp.title,
MAX(salary),
MIN(salary),
AVG(salary),
SUM(salary),
COUNT(*)
FROM emp
GROUP BY emp.title;
SELECT ord.id AS "ID ZLECENIA",
customer.name AS "Klient",
emp.first_name AS "Sprzedawca",
emp.last_name AS "",
date_format(ord.date_ordered,'%W, %Y-%m-%d') AS "DATA",
SUM(item.price * item.quantity) AS "SUMA ZAMÓWIENIA",
COUNT(*) AS "LICZBA POZYCJI"
FROM ord, item, customer, emp
WHERE item.ord_id = ord.id
AND customer.id = ord.customer_id
AND emp.id = ord.sales_rep_id
GROUP BY item.ord_id;
SELECT emp.title,
emp.first_name,
emp.last_name,
emp.salary
FROM emp
WHERE emp.salary > (SELECT AVG(emp.salary)
FROM emp);
SELECT emp.title,
emp.first_name,
emp.last_name,
emp.salary
FROM emp
WHERE (emp.title, emp.salary) = (SELECT 'Warehouse Manager', MIN(emp.salary)
FROM emp
WHERE emp.title = 'Warehouse Manager');
SELECT emp.first_name,
emp.last_name,
emp.salary
FROM emp
WHERE salary < (SELECT AVG(emp.salary) FROM emp)
AND emp.dept_id IN (SELECT dept.id FROM dept WHERE dept.name = 'Sales');
SELECT emp.first_name, emp.last_name
FROM emp
WHERE dept_id IN (SELECT dept.id
FROM dept
WHERE dept.region_id IN ( SELECT region.id
FROM region
WHERE region.name = 'Europe'
)
);
TO SAMO MOŻNA UZYSKAĆ ZA POMOCĄ ZŁĄCZENIA
SELECT emp.first_name,
emp.last_name
FROM emp, dept, region
WHERE emp.dept_id = dept.id
AND dept.region_id = region.id
AND region.name = 'Europe';
SELECT title, SUM(salary)
FROM emp
GROUP BY title
HAVING SUM(salary) > 2000;
SELECT zlec.id AS 'ID',
zlec.customer_name AS 'Klient',
CONCAT(zlec.first_name, ' ',
zlec.last_name) AS 'Sprzedawca',
zlec.manager AS 'Manager',
zlec.date_ordered AS 'Data zlecenia',
zlec.prod_name AS 'Produkt',
zlec.price AS 'Cena',
zlec.quantity AS 'Ilość',
zlec.price * zlec.quantity AS 'Wartość'
FROM (SELECT ord.id,
customer.name AS customer_name,
emp.last_name,
emp.first_name,
man.first_name AS manager,
ord.date_ordered,
item.price,
item.quantity,
product.name AS prod_name
FROM ord INNER JOIN customer ON customer.id = ord.customer_id
INNER JOIN emp ON emp.id = ord.sales_rep_id
INNER JOIN emp AS man ON man.id = emp.manager_id
LEFT OUTER JOIN item ON item.ord_id = ord.id
LEFT OUTER JOIN product ON product.id = item.product_id
) AS zlec;

View file

@ -1,24 +1,16 @@
<?php <select id="Departament" name="dept">
$sql_mgr = "SELECT id, last_name FROM emp"; <?php $dept = '';
$wyn_mgr = mysqli_query($id_conn, $sql_mgr); $w_dept = mysqli_fetch_array($wyn_dept);
if (!$wyn_mgr || mysqli_error($id_conn)) { $deptle = $w_dept['name'];
echo "Błąd w zapytaniu o departamenty: " . $baza . '(' . mysqli_error($id_conn) . ')';
mysqli_close($id_conn);
exit;
}
$ok_mgr = 0;
$mgrs = '';
while ($w_mgr = mysqli_fetch_array($wyn_mgr)) {
if ($w_mgr['id'] == $mid) {
$ok_mgr = 1;
}
$mgrs .= ', <br> -' . $w_mgr['id'] . ", " . $w_mgr['last_name'];
}
if ($ok_mgr == 0) {
echo 'Nie ma menadżera "' . $mid . '", wybierz jeden z poniższych: ';
echo '<br>' . substr($mgrs, 6);
}
?> ?>
<option value=<?php printf("%s", "'" . $deptle . "'"); ?> selected><?php printf("%s", $deptle); ?></option>
<?php
while ($w_dept = mysqli_fetch_array($wyn_dept))
{
$deptle = $w_dept['name'];
?>
<option value=<?php printf("%s", "'" . $deptle . "'"); ?>><?php printf("%s", $deptle); ?></option>
<?php
}
?>
</select>

View file

@ -30,7 +30,14 @@
mysqli_close($id_conn); mysqli_close($id_conn);
exit; exit;
} }
$sql_dept = "SELECT dept.id, dept.name, region.name AS region FROM dept JOIN region ON dept.region_id = region.id;";
$wyn_dept = mysqli_query($id_conn, $sql_dept);
if (mysqli_errno($id_conn))
{
echo "Błąd w zapytania o departament: " . $baza . ' (' . mysqli_error($id_conn) . ')';
mysqli_close($id_conn);
exit;
}
?> ?>
@ -59,7 +66,23 @@
?> ?>
</select> </select>
</td></tr> </td></tr>
<tr><td>Departament:</td><td><input type='text' name='dept_id' ></td></tr> <tr><td>Departament:</td><td>
<select id="Departament" name="dept_id">
<?php $dept = '';
$w_dept = mysqli_fetch_array($wyn_dept);
$deptle = $w_dept['id'] + '|' + $w_dept['name'] + '|' + $w_dept['region'];
?>
<option value=<?php printf("%s", "'" . $deptle . "'"); ?> selected><?php printf("%s", $deptle); ?></option>
<?php
while ($w_dept = mysqli_fetch_array($wyn_dept))
{
$deptle = $w_dept['id'];
?>
<option value=<?php printf("%s", "'" . $deptle . "'"); ?>><?php printf("%s", $deptle); ?></option>
<?php
}
?>
</select></td></tr>
<tr><td>Zarobki: </td><td><input type='text' name='salary' ></td></tr> <tr><td>Zarobki: </td><td><input type='text' name='salary' ></td></tr>
<tr><td>Data: </td><td><input type='text' name='start_dt' ></td></tr> <tr><td>Data: </td><td><input type='text' name='start_dt' ></td></tr>
<tr><td>ID managera:</td><td><input type='text' name='man_id' ></td></tr> <tr><td>ID managera:</td><td><input type='text' name='man_id' ></td></tr>