SELECT
a.Name, a.Eats, a.Drinks
FROM
xd_animals_test a结果
Name Eats Drinks
Elephant NULL Y
Elephant Y NULL获得一个结果的最佳方法是什么?例如
Name Eats Drinks
Elephant Y Y这是我的尝试,我不确定这是不是最干净的方式。有没有其他更有效的方法来做到这一点?
SELECT
Names.Name, Eats, Drinks
FROM
(SELECT DISTINCT
Name
FROM
xd_animals_test) names
LEFT JOIN
(SELECT
MAX(name) AS Name, MAX(eats) AS Eats, MAX(drinks) AS Drinks
FROM
xd_animals_test) eatdrink ON names.Name = EatDrink.Name发布于 2015-10-20 20:43:05
或
Select name,
Case if exists(select * from table
where name = a.name
and Eats ='Y")
then 'Y' end Eats,
Case if exists(select * from table
where name = a.name
and Drinks ='Y")
then 'Y' end Drinks ,
From table ahttps://stackoverflow.com/questions/33236826
复制相似问题