0% found this document useful (0 votes)
13 views2 pages

Query

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Query

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

--LATIHAN 1

SELECT
SUM(price) AS total_pendapatan,
SUM(price-cost)
FROM items;

--LATIHAN 2
SELECT
name,
price,
FROM items
WHERE price <=20 AND gender = 2
ORDER BY price DESC;

--LATIHAN 3
user_id AS pelanggan,
COUNT(item_id) AS jumlah_belanja
FROM sales_records
WHERE purchased_at LIKE '%2018-07%'
GROUP BY user_id
ORDER BY COUNT(item_id) DESC
LIMIT 5;

--LATIHAN 4
SELECT
user_id AS customer,
AVG(price) AS average_shopping_amount
FROM sales_records
JOIN items
ON sales_records.item_id = item.id
GROUP BY user_id
HAVING purchased_at LIKE '%2018-07%'
AND AVG(price) >= 100
ORDER BY AVG(price) DESC
LIMIT 5;

--LATIHAN 5
SELECT
gender,
SUM(price) AS total_pendapatan,
SUM(price-cost) AS total_laba
FROM sales_records
JOIN items
ON sales_records.item_id = items.id
GROUP BY gender;

--LATIHAN 6
SELECT
name,
COUNT(item_id) AS total_penjualan,
price,
price*COUNT(item_id) AS total_pendapatan
FROM items
JOIN sales_records
ON items.id = sales_records.item_id
GROUP BY item_id
ORDER BY price DESC
LIMIT 5;

You might also like