根据int中的数字将一列拆分为两列

erhoui1w  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(290)

这是我目前的代码:

create table client (
  client_id int,
  birth_number int,
  district_id int
  Primary Key (district_id)
);

truncate client;

load data local infile 'C:\\Users\\james\\Desktop\\Wecloud_Data_Bootcamp\\bank_loan\\client.asc'
into table client
fields terminated by ';'
lines terminated by '\n'
ignore 1 lines
(client_id, @birth_number, district_id)
SET birth_number = REPLACE(@birth_number, '"','');

-- Check the table
select * from client;

这是当前表

我需要做的是将birth\u number列分成两列,分别是birthdate和gender。说明如下,可能需要整数操作,如何操作?
问题的说明
列的详细信息

nvbavucw

nvbavucw1#

试试这个:

SELECT 
     DATE_FORMAT(CONCAT(SUBSTR(birth_number, 1, 2), 
          IF(SUBSTR(birth_number, 3, 2) > 50, 
          SUBSTR(birth_number, 3, 2) - 50, SUBSTR(birth_number, 3, 2)), 
          SUBSTR(birth_number, 5, 2)),
         '%Y-%M-%d'
     ) AS `date`, 
     IF(SUBSTR(birth_number, 3, 2) > 50, 'Female', 'Male') AS Gender
FROM `client`

根据您的要求更改日期格式。

相关问题