Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL server:如何清晰地组合行_Mysql_Sql_Join - Fatal编程技术网

Mysql SQL server:如何清晰地组合行

Mysql SQL server:如何清晰地组合行,mysql,sql,join,Mysql,Sql,Join,我的表格中的数据是: **country 2010 2011 2012** Argentina NULL NULL true Argentina NULL true NULL Argentina true NULL NULL Bolivia NULL NULL true Bolivia NULL true NULL Bolivia NULL NULL NULL C

我的表格中的数据是:

**country       2010    2011     2012**
Argentina   NULL    NULL    true
Argentina   NULL    true    NULL
Argentina   true    NULL    NULL
Bolivia     NULL    NULL    true
Bolivia     NULL    true    NULL
Bolivia     NULL    NULL    NULL
Canada      NULL    NULL    true
Canada      NULL    NULL    NULL
Canada      true    NULL    NULL
我想要的是删除“null”并合并数据中的“true”,使其看起来像:

**country       2010    2011     2012**
Argentina   true    true    true
Bolivia     NULL    true    true
Canada      true    NULL    true

我想我必须对这个语句,甚至可能是case语句使用自连接,但我不确定从何处开始。

您应该能够使用带有聚合的
max()

select country, max(`2010`) as `2010`, max(`2011`) as `2011`, max(`2012`) as 2012
from t
group by country;

您应该能够使用带有聚合的
max()
来执行此操作:

select country, max(`2010`) as `2010`, max(`2011`) as `2011`, max(`2012`) as 2012
from t
group by country;

什么数据类型是
true
?只有NULL/true两个值?是。NULL/TRUE只不过是仔细考虑重新设计你的模式。什么样的数据类型是代码>真的< /COD>?NULL/TRUE是唯一的两个值?是的。NULL/TRUE是唯一考虑重新设计模式的唯一方法。