gpt4 book ai didi

mysql - 一个嵌套 sql 查询中的两个查询

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

我想把两条sql语句合二为一。第一个显示每天下达的订单总数,第二个仅显示每天有员工作为操作文本的订单数。

select date(dated) date_ord, count(*) as orders_placed
from stats.sales_actions
group by date_ord
order by dated desc

select date(dated) date_order, count(*) as orders_modified
from stats.sales_actions
where action_text LIKE '%STAFF%'
group by date_ord
order by dated desc

如果可能,我想在一个表/sql 查询中显示。

最佳答案

只需使用UNION:

select date(dated) date_ord, count(*), 'orders_places' as orders_placed
from stats.sales_actions
group by date_ord
order by dated desc
UNION
select date(dated) date_order, count(*), 'orders_modified' as orders_modified
from stats.sales_actions
where action_text LIKE '%STAFF%'
group by date_ord
order by dated desc

关于mysql - 一个嵌套 sql 查询中的两个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9111584/

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