gpt4 book ai didi

mysql - 在具有多列的一个查询中选择两个查询

转载 作者:行者123 更新时间:2023-12-04 14:51:28 26 4
gpt4 key购买 nike

我遇到了一个问题,我想在一个查询中选择两个不同的查询但不同的列注意:不像 union 因为 union 将这两个查询放在一列中

select count(id) as lead,SUM(ol.publisher_earned) as earning from offer_process as ol 
where ol.status='Approved' and ol.publisher_id='1738' and ol.created_at>='2021-08-01' GROUP by date(ol.created_at)

select count(ol2.id) as clicks from offer_process as ol2 where ol2.publisher_id='1738' and ol2.created_at>='2021-08-01' GROUP by date(ol2.created_at)

最佳答案

请检查这个。如果 created_date 在 SELECT 子句中不需要,则丢弃它。

SELECT date(created_at) created_at
, COUNT(publisher_id) clicks
, SUM(CASE WHEN status='Approved' THEN publisher_earned ELSE 0 END) earning
FROM offer_process
WHERE publisher_id='1738'
AND created_at>='2021-08-01'
GROUP BY date(created_at)

关于mysql - 在具有多列的一个查询中选择两个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69008289/

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