Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Two query in one query with multiple column

I am getting the issue I want to select two different queries in one query but different column Note: Not like union because union put these two queries in one column

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)
like image 665
Habib Ur Rehman Avatar asked Apr 23 '26 12:04

Habib Ur Rehman


1 Answers

Please check this. If created_date isn't need at SELECT clause then discard it.

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)
like image 158
Rahul Biswas Avatar answered Apr 25 '26 06:04

Rahul Biswas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!