sql - Mysql logic - how to change the selected value based on the data? -


i trying populate table phone number temp table. have wrote query no problem. peoblem here know if company has primary number or not

so select 2 fields temp table called "cvsnumbers" 1) company_code (id) , phone number.

i need add case statement change value of main_number field. if number has number main_number = 1 need insert 0 new phone number if there no main_number need insert 1 new phone number making primary phone number account.

this query

    select ac.account_id,            replace(replace(replace(replace(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') phone,            ifnull(ta.ext, '') extention,            ifnull(ta.main_number, 0) mainnumber,            ta.type contact_type,            '2' created_by       cvsnumbers ta inner join accounts ac on ac.account_id = ta.company_code      length(replace(replace(replace(replace(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') ) = 10        , replace(replace(replace(replace(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') not in (select contact_number contact_numbers) 

my issue

`ifnull(ta.main_number, 0) mainnumber,` 

i want change case statment check if company_code has main_number or not.

how can change this?

thanks

i still not sure how query should like, how along theese lines?

select case              when exists (select *                            contact_numbers                           main_number = 1                             , contact_number =                             <insert contact number outer expression here>)              1             else 0         end mainnumber   ... 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -