mysqlm
anhhackta
mysql
2 years ago
774 B
10
Indexable
SELECT * FROM customers;
select * from customers where country = "Japan";
select * from orderdetails where priceEach between 99 and 100;
select * from customers where contactLastName like 'A%';
-- Tạo bảng tạm với LIMIT để chứa customerNumber của 3 bản ghi đầu tiên
CREATE TEMPORARY TABLE temp_customer_numbers AS
SELECT customerNumber
FROM customers
LIMIT 3;
SELECT *
FROM customers
WHERE customerNumber NOT IN (
SELECT customerNumber
FROM temp_customer_numbers
);
SELECT customerNumber, MAX(tong) as max_tong
FROM (
SELECT customerNumber, SUM(amount) as tong
FROM payments
GROUP BY customerNumber
) AS subquery
GROUP BY customerNumber
ORDER BY max_tong DESC
LIMIT 1;
Editor is loading...
Leave a Comment