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是唯一考虑重新设计模式的唯一方法。