【问题标题】:sqlite creating new rows based on column conditionssqlite 根据列条件创建新行
【发布时间】:2016-08-16 16:43:58
【问题描述】:

我收到这样的数据库:

Product   Condition1   Condition2   Condition 3
Computer  1            2           
Car       1            2            3

他们希望我以这种形式导出数据库:

Product   Condition
Computer  1
Computer  2
Car       1
Car       2
Car       3

这是大量数据,手动修复内容没有任何意义。你知道我将如何获得动态解决方案。非常感谢您的帮助。

【问题讨论】:

    标签: sql sqlite conditional database-schema


    【解决方案1】:

    这应该可行:

    SELECT product, condition1 FROM table_name
    UNION SELECT product, condition2 FROM table_name
    UNION SELECT product, condition3 FROM table_name
    UNION ORDER BY product
    

    【讨论】:

    • 需要在ORDER BY前去掉最后一个UNION
    猜你喜欢
    • 2020-10-02
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2021-06-11
    • 1970-01-01
    相关资源
    最近更新 更多