Select 一个多列查询中的两个查询
Select Two query in one query with multiple column
我遇到了问题,我想 select 一个查询中有两个不同的查询,但列不同
注意:不像 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)
SELECT earning,clicks FROM
(
select ol.publisher_id,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),ol.publisher_id
)ol
JOIN
(
select ol2.publisher_id, 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),ol2.publisher_id
)ol2 On ol.publisher_id=ol2.publisher_id
请检查这个。如果 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)
我遇到了问题,我想 select 一个查询中有两个不同的查询,但列不同 注意:不像 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)
SELECT earning,clicks FROM
(
select ol.publisher_id,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),ol.publisher_id
)ol
JOIN
(
select ol2.publisher_id, 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),ol2.publisher_id
)ol2 On ol.publisher_id=ol2.publisher_id
请检查这个。如果 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)