SELECT DISTINCT NAME
FROM EMPLOYEE
WHERE (NAME, PHONE, AGE) IN (
SELECT NAME, PHONE, AGE
FROM EMPLOYEE
GROUP BY NAME, PHONE, AGE
HAVING COUNT(*) > 1
);
----------------------------------------------------------------------
SELECT a.email,
TRUNCATE(SUM(r.amount), 2) AS total_report_amount
FROM accounts a
JOIN reports r ON a.id = r.account_id
WHERE SUBSTR(r.dt, 1, 4) = '2023'
GROUP BY a.email
ORDER BY a.email;
----------------------------------------------------------------------
SELECT p.name AS product_name, COUNT(r.product_id) AS
total_requests
FROM products p
JOIN requests r ON p.id = r.product_id
WHERE p.is_available = 1
GROUP BY p.name
ORDER BY total_requests DESC, product_name ASC;
----------------------------------------------------------------------
SELECT
a.iban,
COUNT(t.amount) AS transaction_count,
ROUND(SUM(t.amount),2) AS total_transaction_sum
FROM
accounts a
JOIN
transactions t ON a.id = t.account_id
WHERE
t.transactions_date >= '2022-09-01'
AND t.transactions_date <= '2022-09-30'
GROUP BY
a.iban
ORDER BY
total_transaction_sum DESC;
--------------------------------------------------------------------
SELECT
l.name AS lot_name,
COUNT(a.amount) AS number_of_offers,
MIN(a.amount) AS min_offer,
MAX(a.amount) AS max_offer,
AVG(a.amount) AS avg_offer
FROM
lots l
JOIN
amounts a ON l.id = a.id
GROUP BY
l.name;
----------------------------------------------------------------------
SELECT *,
CASE WHEN red = green AND green = blue THEN 'GOOD'
WHEN red = green OR green = blue OR red = blue THEN
'WORSE'
ELSE 'BAD'
END AS Result
FROM collections;
----------------------------------------------------------------------
SELECT CONCAT(p.first_name, ' ', p.last_name) AS full_name,
p.email,
SUM(CASE WHEN r.approved = 1 THEN 1 ELSE 0 END) AS
total_approvals,
SUM(CASE WHEN r.approved = 0 THEN 1 ELSE 0 END) AS
not_approved,
COUNT(r.approved) AS total_requests
FROM profile AS p
LEFT JOIN relation AS r ON r.profile_id = p.id
GROUP BY p.first_name, p.last_name, p.email;
----------------------------------------------------------------------
SELECT c.Name from COMPANY c join SALARY s on c.id=s.
COMPANY ID GROUP by c.name having avg(s.SALARY)>40000;
----------------------------------------------------------------------
Select
c.name as campaign_name,
count(e.campaign_id) as total_engagements,
sum(e.views+e.clicks) as total_views_and_clicks
from campaigns c
join
engagements e on c.id=e.campaign_id
where
c.is_active=1
group by
c.name
order by
c.name asc;