0

我有多个表+不同的字段,我尝试做这样的事情:

SELECT
   `title` as title,
   `manufacturer`+`model` as content /* I want to achieve this as well */
   `type` = 'auto_table' /* custom variable w/ value auto_table to know from where is this data*/
    FROM `auto`
    WHERE `title` LIKE '%bmw%'
    OR
    `manufacturer` LIKE '%bmw'
    OR
    `other_data` LIKE '%bmw'
UNION
    SELECT
       `title` as title,
       `content` as content
       `type` = 'news_page' /* custom variable w/ value news_page to know from where is this data*/
        FROM `news`
        WHERE `title` LIKE '%bmw%'
        OR
        `content` LIKE '%bmw'

我的意思是我想在动态选择期间添加一行及其值。另一个我想将两个字段组合成一个像manufacturer+ modelastitle

4

3 回答 3

1

CONCAT (manufacturer, model) as content

于 2012-12-14T13:34:35.253 回答
0

试试这个:

SELECT
   title,
   CONCAT(manufacturer,model) as content
   'auto_table' as type
FROM [...]
于 2012-12-14T13:34:21.707 回答
0

很难得到你真正想要的东西。是要一次性插入选择吗?

INSERT INTO your_table
SELECT
   `title` as title,
   CONCAT(`manufacturer`,' ', `model`) as content /* I want to achieve this as well */
   `type` = 'auto_table' /* custom variable w/ value auto_table to know from where is this data*/
    FROM `auto`
    WHERE `title` LIKE '%bmw%'
    OR
    `manufacturer` LIKE '%bmw'
    OR
    `other_data` LIKE '%bmw'
UNION
    SELECT
       `title` as title,
       `content` as content
       `type` = 'news_page' /* custom variable w/ value news_page to know from where is this data*/
        FROM `news`
        WHERE `title` LIKE '%bmw%'
        OR
        `content` LIKE '%bmw'

使用 CONCAT 连接值

于 2012-12-14T13:37:01.507 回答