连接列将存储在两个不同的列中

时间:2015-05-12 06:53:39

标签: mysql

我有一个网站,当客户在其上注册时,数据存储在管理面板中,现在如果您在第一行中看到下面的代码,emp_name和emp_ID保存在一个列中,我想保存它在两个不同的栏目中如何区分它。

$sql = "SELECT c.customer_id, CONCAT(c.emp_name, ' ', c.emp_ID) AS name,
 c.email, c.mobile_no, CONCAT(oca.address_1,oca.address_2) AS address, 
 oca.city, oca.postcode, occ.name as Country, c.ip,
IF( c.status = 1, 'Enabled','Disabled' ) AS status, 
IF( c.approved = 1, 'Yes', 'No' ) AS approved, c.date_added, cgd.name AS customer_group FROM " . DB_PREFIX . "customer c 
LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (c.customer_group_id = cgd.customer_group_id) 
LEFT JOIN " . DB_PREFIX . "address oca ON (c.address_id=oca.address_id) 
LEFT JOIN " . DB_PREFIX . "country occ ON (oca.country_id=occ.country_id) 
WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT c.customer_id, 
       c.emp_id, 
       c.emp_name AS NAME, 
       c.email, 
       c.mobile_no, 
              Concat(oca.address_1,oca.address_2) AS address, 
       oca.city, 
       oca.postcode, 
       occ.NAME AS Country, 
       c.ip,IF( c.status = 1, 'Enabled', 'Disabled' ) as status, 
IF( c.approved = 1, 'Yes', 'No' ) AS approved, c.date_added, cgd.NAME AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (
  c.customer_group_id = cgd.customer_group_id 
) 
LEFT JOIN " . DB_PREFIX . "address oca ON ( 
  c.address_id=oca.address_id 
) 
LEFT JOIN " . DB_PREFIX . "country occ ON ( 
  oca.country_id=occ.country_id 
) 
WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'

MySQL CONCAT()函数用于连接两个或多个字符串以形成单个字符串。这就是您在单个列中查看数据的原因。如果要在单独的列中显示数据,只需删除该功能。