可以使用以下SQL语句来新建顾客统计表'cusshopping',并插入每个顾客的编号、购物总数量和购物总价:

-- 创建'cusshopping'表
CREATE TABLE cusshopping (
  customer_id INT,
  total_quantity INT,
  total_price DECIMAL(10,2)
);

-- 插入数据到'cusshopping'表
INSERT INTO cusshopping (customer_id, total_quantity, total_price)
SELECT customer_id, SUM(quantity) AS total_quantity, SUM(price) AS total_price
FROM shopping
GROUP BY customer_id;

请注意,上述SQL语句中的'shopping'表示原始的购物表,其中包含了顾客编号、购买数量和价格等信息。你需要根据实际情况修改表名和列名。

SQL: 创建顾客统计表并插入数据

原文地址: https://www.cveoy.top/t/topic/pgSG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录