gpt4 book ai didi

mysql - 如何排除列出现在结果中?

转载 作者:行者123 更新时间:2023-11-29 04:34:25 25 4
gpt4 key购买 nike

此查询返回季度销售额,但我想隐藏 order_date 列以免出现在结果中。 order_date 仅用于确定商品是否在该季度内购买。

SELECT item.item_id, item.item_name, item.item_type, item.item_price, SUM(orderdetail.order_quantity) AS 'Quantity Ordered', 
SUM(item.item_price*orderdetail.order_quantity) AS 'Total Sales Per Item', orders.order_date FROM item
JOIN orderdetail ON item.item_id = orderdetail.item_id
JOIN orders ON orderdetail.order_id = orders.order_id
GROUP BY item.item_id, item.item_name, item.item_price, item.item_type
HAVING order_date BETWEEN '2017-01-01' AND '2017-03-31'
ORDER BY item.item_id;

最佳答案

只需将其从select 列表中删除即可。这不会阻止您在 wherehaving 子句中使用它:

SELECT item.item_id, item.item_name, item.item_type, item.item_price, SUM(orderdetail.order_quantity) AS 'Quantity Ordered', 
SUM(item.item_price*orderdetail.order_quantity) AS 'Total Sales Per Item'
-- order_date removed here
FROM item
JOIN orderdetail ON item.item_id = orderdetail.item_id
JOIN orders ON orderdetail.order_id = orders.order_id
GROUP BY item.item_id, item.item_name, item.item_price, item.item_type
HAVING order_date BETWEEN '2017-01-01' AND '2017-03-31'
ORDER BY item.item_id;

关于mysql - 如何排除列出现在结果中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47612562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com