중앙일보 Yellowpage after combined_output_02


delete from combined_output_02 where field1 like 'field%'


ALTER TABLE combined_output_02
ADD COLUMN field9 TEXT;

ALTER TABLE combined_output_02
ADD COLUMN URL TEXT;

ALTER TABLE combined_output_02
ADD COLUMN AreaCode TEXT;

ALTER TABLE combined_output_02
ADD COLUMN TEL TEXT;

UPDATE combined_output_02
SET field8 = field7
WHERE field8 IS NULL;
UPDATE combined_output_02
SET URL = 
    CASE 
        WHEN field7 LIKE 'URL%' THEN field7
        WHEN field6 LIKE 'URL%' THEN field6
        WHEN field5 LIKE 'URL%' THEN field5
        WHEN field4 LIKE 'URL%' THEN field4
        ELSE URL -- Keep the existing URL value if none of the conditions are met
    END;
update combined_output_02 set URL = substr(URL, -length(URL) + 5)
copy phone TEL: xxx-xxx-xxx:

UPDATE combined_output_02
SET field9 = 
    CASE 
        WHEN field5 LIKE 'TEL:%' AND LENGTH(field5) = 17 THEN field5
        WHEN field4 LIKE 'TEL:%' AND LENGTH(field4) = 17 THEN field4
        WHEN field6 LIKE 'TEL:%' AND LENGTH(field6) = 17 THEN field6
        ELSE field9 -- Keep the existing value of field9 if none of the conditions are met
    END;

reformat phone TEL: (xxx) xxx-xxxx:

UPDATE combined_output_02
SET field9 = 
    CASE 
        WHEN field5 LIKE 'TEL%(%)%' AND LENGTH(field5) = 19 THEN
            SUBSTR(field5, 1, 5) || SUBSTR(field5, 7, 3) || '-' || SUBSTR(field5, 12, 3) || '-' || SUBSTR(field5, -4)
        WHEN field4 LIKE 'TEL%(%)%' AND LENGTH(field4) = 19 THEN
            SUBSTR(field4, 1, 5) || SUBSTR(field4, 7, 3) || '-' || SUBSTR(field4, 12, 3) || '-' || SUBSTR(field4, -4)
        WHEN field6 LIKE 'TEL%(%)%' AND LENGTH(field6) = 19 THEN
            SUBSTR(field6, 1, 5) || SUBSTR(field6, 7, 3) || '-' || SUBSTR(field6, 12, 3) || '-' || SUBSTR(field6, -4)
        ELSE
            field9 -- Keep the existing value of field9 if none of the conditions are met
    END;

reformat phone TEL: (xxx)xxx-xxxx:

UPDATE combined_output_02
SET field9 = 
    CASE 
        WHEN field5 LIKE 'TEL%(%)%' AND LENGTH(field5) = 18 THEN
            SUBSTR(field5, 1, 5) || SUBSTR(field5, 7, 3) || '-' || SUBSTR(field5, 11, 3) || '-' || SUBSTR(field5, -4)
        WHEN field4 LIKE 'TEL%(%)%' AND LENGTH(field4) = 18 THEN
            SUBSTR(field4, 1, 5) || SUBSTR(field4, 7, 3) || '-' || SUBSTR(field4, 11, 3) || '-' || SUBSTR(field4, -4)
        WHEN field6 LIKE 'TEL%(%)%' AND LENGTH(field6) = 18 THEN
            SUBSTR(field6, 1, 5) || SUBSTR(field6, 7, 3) || '-' || SUBSTR(field6, 11, 3) || '-' || SUBSTR(field6, -4)
        ELSE
            field9 -- Keep the existing value of field9 if none of the conditions are met
    END;
UPDATE combined_output_02
SET AreaCode = substr(field9, 6, 3)
update combined_output_02 set TEL = substr(field9, -12) where field9 is not null
select combined_output_02.* , AreaCode_TimeZone.StandardTimeZone from combined_output_02 LEFT join AreaCode_TimeZone on combined_output_02.AreaCode = AreaCode_TimeZone.AreaCode
SELECT MIN(ID) AS min_ID, TEL
FROM combined_output_02_timezone
GROUP BY TEL
select * from combined_output_02_timezone where ID in (select min_ID from unique_phone)