AS time, YEAR(paymentDate) AS year, MONTH(paymentDate) AS month, MONTHNAME(paymentDate) AS monthName, WEEK(paymentDate) AS week, DAYOFMONTH(paymentDate) AS dayOfMonth, WEEKDAY(paymentDate) AS dayOfWeek, DAYNAME(paymentDate) AS dayName, HOUR(paymentDate) AS hour, MINUTE(paymentDate) AS minute, SECOND(paymentDate) AS second FROM payments;
currentTimestamp, CURRENT_DATE() AS currentDate, CURRENT_TIME() AS currentTime, CURRENT_DATE() + INTERVAL 1 DAY AS tomorrow, NOW() + INTERVAL 3 MONTH AS threeMonthsLater, CURRENT_TIME() + INTERVAL 2 HOUR AS twoHoursLater;
and the exact duration between the required date and shipped date for each order. Then, list the orders that were shipped less than 72 hours before the required date.
MAX(orderDate) AS lastOrderDate FROM customers c JOIN orders o ON c.customerNumber = o.customerNumber WHERE o.orderDate >= '2004-04-01' GROUP BY c.customerNumber HAVING numOrders > 3;
SUM(od.quantityOrdered * od.priceEach) AS orderValue FROM orders o JOIN orderDetails od ON od.orderNumber = o.orderNumber WHERE YEAR(o.shippedDate) = 2003 AND status = 'Shipped' GROUP BY o.orderNumber)
sales FROM orderValues ov JOIN customers c ON ov.customerNumber = c.customerNumber JOIN employees e ON c.salesRepEmployeeNumber = e.employeeNumber GROUP BY c.salesRepEmployeeNumber ORDER BY sales DESC LIMIT 5;
0 THEN "New" WHEN 1 THEN "One-time" WHEN 2 THEN "Repeat" ELSE "Loyal" END AS customerType FROM customers c LEFT OUTER JOIN orders o ON c.customerNumber = o.customerNumber GROUP BY c.customerNumber ORDER BY orders DESC;
'Shipped' THEN 1 ELSE 0 END) AS 'Shipped', SUM(CASE WHEN status = 'On Hold' THEN 1 ELSE 0 END) AS 'On Hold', SUM(CASE WHEN status = 'In Process' THEN 1 ELSE 0 END) AS 'In Process', SUM(CASE WHEN status = 'Resolved' THEN 1 ELSE 0 END) AS 'Resolved', SUM(CASE WHEN status = 'Cancelled' THEN 1 ELSE 0 END) AS 'Cancelled', SUM(CASE WHEN status = 'Disputed' THEN 1 ELSE 0 END) AS 'Disputed', COUNT(orderNumber) AS 'Total' FROM orders NATURAL JOIN customers GROUP BY customerNumber ORDER BY customerName;
SELECT o.orderNumber, o.customerNumber, o.orderDate, ROUND(SUM(od.priceEach * od.quantityOrdered), 2) AS orderValue FROM orders o JOIN orderDetails od ON o.orderNumber = od.orderNumber WHERE o.customerNumber = custNo GROUP BY orderNumber; END$$ DELIMITER ;
DETERMINISTIC BEGIN DECLARE size VARCHAR(10); IF amount <= 10000 THEN SET size = 'Small'; ELSEIF amount <= 50000 THEN SET size = 'Medium'; ELSE SET size = 'Large'; END IF; RETURN size; END$$ DELIMITER ;
paymentCount FROM payments GROUP BY paymentSize; -- Deletion DROP FUNCTION IF EXISTS PAYMENT_SIZE; — Listing SHOW FUNCTION STATUS WHERE db = 'classicmodels';
e.jobTitle, e.reportsTo FROM employees e WHERE e.employeeNumber = 1401 UNION ALL SELECT e.employeeNumber, e.lastName, e.firstName, e.jobTitle, e.reportsTo FROM employees e JOIN employeeChain ec ON e.employeeNumber = ec.reportsTo ) SELECT * FROM employeeChain;