Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
表 1 颜色
和另一张桌子最喜欢的颜色
现在我想要输出为
我怎样才能得到这个
像这样的东西怎么样
SELECT f.favColorID, c.Color, CASE WHEN c.colorid = f.colorid THEN 'YES' ELSE 'NO' END IsFavorite FROM tblColours c, tblFavColours f ORDER BY 1
看看使用CASE 语法
我可以用 T-SQL 方言(Microsoft SQL-Server)给你答案。这case when部分在其他方言中可能有所不同。
case when
select f.favColorID, c.Color, case when f.ColorID=c.ColorID then 'YES' else 'NO' end as IsFavorite from colors c cross join favoriteColor f order by f.favColorID