SELECT enq_entry_date, enq_showroom_id, COUNT( CASE WHEN enq_mode_enq = 9 THEN 1 ELSE NULL END ) AS Walkin, COUNT( CASE WHEN enq_mode_enq = 1 THEN 1 ELSE NULL END ) AS cug_rd_in, COUNT( CASE WHEN enq_mode_enq = 18 THEN 1 ELSE NULL END ) AS cug_own, COUNT( CASE WHEN enq_mode_enq = 8 THEN 1 ELSE NULL END ) AS fst_trk_print_adv, COUNT( CASE WHEN enq_mode_enq = 2 THEN 1 ELSE NULL END ) AS whatsApp, COUNT( CASE WHEN enq_mode_enq = 5 THEN 1 ELSE NULL END ) AS EVENTS, COUNT( CASE WHEN enq_mode_enq = 7 THEN 1 ELSE NULL END ) AS olx_rd, COUNT( CASE WHEN enq_mode_enq = 19 THEN 1 ELSE NULL END ) AS olx_own, COUNT( CASE WHEN enq_mode_enq = 4 THEN 1 ELSE NULL END ) AS fb_rd, COUNT( CASE WHEN enq_mode_enq = 20 THEN 1 ELSE NULL END ) AS fb_own, COUNT( CASE WHEN enq_mode_enq = 23 THEN 1 ELSE NULL END ) AS insta, COUNT( CASE WHEN enq_mode_enq = 6 THEN 1 ELSE NULL END ) AS other_referal_own_dbt, COUNT( CASE WHEN enq_mode_enq = 21 THEN 1 ELSE NULL END ) AS other_telecall_rd_dbt, COUNT( CASE WHEN enq_mode_enq = 26 THEN 1 ELSE NULL END ) AS other_Web_enq_RD_OUT, COUNT( CASE WHEN enq_mode_enq = 22 THEN 1 ELSE NULL END ) AS other_Web_enq_google, COUNT( CASE WHEN enq_mode_enq = 24 THEN 1 ELSE NULL END ) AS other_Web_enq_india_mart, COUNT( CASE WHEN enq_mode_enq = 15 THEN 1 ELSE NULL END ) AS other_Web_just_dial, COUNT( CASE WHEN enq_mode_enq = 16 THEN 1 ELSE NULL END ) AS other_Web_enq_car_wale, COUNT( CASE WHEN enq_mode_enq = 14 THEN 1 ELSE NULL END ) AS other_Web_enq_car_trade FROM cpnl_enquiry WHERE MONTH(cpnl_enquiry.enq_entry_date) = mnth AND YEAR(cpnl_enquiry.enq_entry_date)=year(curdate()) AND cpnl_enquiry.enq_showroom_id=shrm GROUP BY enq_entry_date


Greater or less:-

SELECT val_id FROM cpnl_valuation WHERE datediff(current_date,date(val_purchased_date)) > 60 AND val_type=1 AND val_re_evaluated=0


SELECT DATEDIFF(current_date,date(val_purchased_date)) AS days_in_stock ,val_id,val_purchased_date,val_veh_no,val_model_year,val_km,val_is_sold,val_sold_date FROM cpnl_valuation WHERE ( datediff(current_date,date(val_purchased_date)) > no AND val_is_sold=0 AND val_re_evaluated=0) Or ( datediff(current_date,date(val_purchased_date)) > no AND val_is_sold=1 AND MONTH(cpnl_valuation.val_sold_date) =mnth AND val_re_evaluated=0 )


If condition

SELECT IF(val_is_sold =1, DATEDIFF(date(val_sold_date),date(val_purchased_date)), DATEDIFF(current_date,date(val_purchased_date))) AS Day_in_stock,val_id,val_purchased_date,val_veh_no,val_model_year,val_km,val_is_sold,val_sold_date,val_showroom FROM cpnl_valuation WHERE ( ( datediff(current_date,date(val_purchased_date)) > no AND val_is_sold=0 AND val_re_evaluated=0) Or ( datediff(current_date,date(val_purchased_date)) > no AND val_is_sold=1 AND MONTH(cpnl_valuation.val_sold_date) =mnth AND val_re_evaluated=0 )) AND cpnl_valuation.val_showroom=shrm

Fetch Last month records SELECT * FROM `cpnl_enquiry` WHERE YEAR(enq_entry_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND MONTH(enq_entry_date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)