php - I want to get each month expense from three table -


i have 3 table named "salary", "allowance" , "bill".

"salary" table has

 s_id [primary key], e_id, s_amount, s_date. 

"allowanace" table has

 a_id[primary key], e_id, a_ta, a_da, a_ma, a_others, a_date, total_a 

"bill" table has

 e_id[primary key], electric, gas, water, b_others, b_date total_b  

i have joined these tables query>>

 select       sum(allowance.`a_ta`+allowance.`a_da`      +allowance.`a_ma`+allowance.`a_others`)      total_allowance,       (sum(salary.`s_amount`)) total_salary,        sum(bill.`electric`+bill.`water`+bill.`gas`+bill.`b_others`)        total_bill,      (sum(allowance.`a_ta`+allowance.`a_da`+allowance.`a_ma`       +allowance.`a_others`)+sum(salary.`s_amount`)       +sum(bill.`electric`+bill.`water`+bill.`gas`+bill.`b_others`))       total_ex        salary       inner join allowance       on salary.e_id=allowance.e_id        inner join bill       on salary.s_date=bill.b_date 

i want total expense "total_ex" of january 2015, december 2015, october 2016, november 2016...each month's total expense separately.

try using sum , if:

sum(if(date_format(salary.s_date,'%m')='january', allowance.a_ta+allowance.a_da+allowance.a_ma +allowance.a_others +salary.s_amount+bill.electric+bill.water +bill.gas+bill.b_others,0))  jan_total_ex 

this give jan total expense.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -