在MySQL中,可以使用整数类型(如TINYINT、SMALLINT、MEDIUMINT、INT和BIGINT)来存储整数值
CREATE TABLE sales_data (
id INT AUTO_INCREMENT PRIMARY KEY,
product_id INT,
quantity_sold INT,
price_per_unit DECIMAL(10, 2)
);
INSERT INTO sales_data (product_id, quantity_sold, price_per_unit)
VALUES (1, 10, 99.99),
(2, 5, 49.99),
(3, 20, 199.99),
(1, 30, 99.99),
(2, 15, 49.99);
SELECT product_id, SUM(quantity_sold) as total_sales
FROM sales_data
GROUP BY product_id;
SELECT product_id, AVG(price_per_unit) as average_price
FROM sales_data
GROUP BY product_id;
SELECT product_id, SUM(quantity_sold) as total_sales
FROM sales_data
GROUP BY product_id
ORDER BY total_sales DESC
LIMIT 1;
SELECT product_id, SUM(quantity_sold * price_per_unit) as total_revenue
FROM sales_data
GROUP BY product_id
ORDER BY total_revenue DESC
LIMIT 1;
这些示例展示了如何使用MySQL整数类型进行简单的数据分析。实际应用中,你可能需要根据具体需求编写更复杂的查询语句。