Get status based on other table column value mysql -
i have 2 tables. job_table.
job_id job_type job_type user job_time job_name 1 1 day user1 2015-04-23 23:20:10 job1 2 2 night user2 2015-04-23 13:20:10 job2 3 3 day & night. user3 2015-04-22 23:10:10 job3 4 3 day & night. user3 2015-04-20 13:40:10 job4 5 1 day user4 2015-04-26 03:20:10 job5
and task_entry table.
task_entry_id job_id task_option_type emp_id completed_task_count status 1 1 day 101 10 1 2 1 day 102 0 0 3 1 day 103 5 1 4 2 night 101 20 1 5 3 day 101 4 1 5 3 night 101 0 0 6 3 day 102 10 1 7 3 night 102 5 1
if job_type of job_table 3 there 2 entries in task_entry table 1 day , 1 night. else 1 entry.
that if job_type 3 count should count/2. (day&night). else count should normal count.
i want status based on job_id. if task_entry job_id 1 status should 'complete' else 'pending'
, total completed_task_count.
job_id task_entry_count status completed_task_count 1 3 pending 15 2 1 complete 20 3 2 pending 19
how can that.
try query
select job_id,count(task_entry_count),case when a.job_id null 'compeletd' else 'pending'end status,sum(completed_task_count) task_table join (select job_id task_table status=0) a.job_id =task_table.job_id group job_id
Comments
Post a Comment