MySQL 创建表选择列=null 的条目(如果存在),否则另一个适当的条目

标签 mysql sql

create table if not exists table1
    (key ind_name(some_id))
    select *
    from table0
    group by some_id;

if (there is an appropriate entry with column1 NULL) : select it
else : select any another appropriate entry

非常感谢您的帮助,因为我对如何在 MySQL 中编写此内容感到困惑。

更新:我最终创建了一个表 table0_temp,其中的条目按照我想要的方式排序,然后在上面的查询中使用它。

create
temporary table if not exists table0_temp
    select * from table0
        order by column1 asc;  

最佳答案

我不确定您在问什么,但我猜您正在搜索以下内容:

SELECT COALESCE(orphan_code ,'appropriate entry');

如果COALESCE不为空,则COALESCE将返回orph​​an_code,否则将返回“适当的条目”。

关于MySQL 创建表选择列=null 的条目(如果存在),否则另一个适当的条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46366967/

相关文章:

SQL 开发人员状态 : Failure - I/O Test failed: The Network Adapter could not establish the connection

sql - 逐行显示

mysql - MySQL 中何时使用单引号、双引号和反引号

mysql - MySQL 触发器未正确计算总和

mysql - 我需要在下面的 sql 查询中使用什么类型的连接来检索正确的结果?

php - 此 PDO 代码如何防止 SQL 注入(inject)?

mysql - 如何为连接指定特定的列?

java - 是否可以通过我的 Eclipse 项目一次在表中插入多个列的值?

php - 我的查询出了什么问题?

mysql - MySql 中的通配符类型