【问题标题】:MySQL select from specific valuesMySQL 从特定值中选择
【发布时间】:2019-03-22 09:55:51
【问题描述】:

我正在尝试执行一个查询,将文字值列表转换为结果集,但如果不进行联合,我无法完全弄清楚语法。

以下是我尝试过的几件事:

SELECT *
FROM (1, 2, 3, 5, 6) temp(id);

select x.* from 
(('test-a1', 'test-a2'), ('test-b1', 'test-b2'), ('test-c1', 'test-c2')) x(col1, col2);

我期望的结果集如下所示:

id
1
2
3
4
5
etc…

col1 | col2
test-a1, test-a2
test-b1, test-b2
test-c1, test-c2
etc…

【问题讨论】:

    标签: jquery mysql database


    【解决方案1】:
    CREATE TEMPORARY TABLE temp_id_table
    ( id INT UNSIGNED NOT NULL );
    
    INSERT INTO temp_id_table ( id ) VALUES
    (1),(2),(3),(4),(5)
    ;
    
    select id from temp_id_table;
    

    结果:

    id
    1
    2
    3
    4
    5
    

    【讨论】:

      【解决方案2】:

      创建一个临时表,将这些值插入到临时表中,然后查询您的临时表。

      【讨论】:

        猜你喜欢
        • 2012-05-14
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 2022-10-14
        • 1970-01-01
        • 1970-01-01
        • 2017-05-17
        • 1970-01-01
        相关资源
        最近更新 更多