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.
我需要搜索有关记录的“开发者”和“发布者”。他们都在同一张桌子上。我可以使用唯一查询进行搜索还是必须搜索两次?
我希望是这样的:
SELECT * FROM developers WHERE id_dev = 1 AS developer AND id_dev = 2 AS publisher
您可以使用 case 语句来输出 developer或publisher根据id_dev列:
developer
publisher
id_dev
SELECT *, case when id_dev = 1 then 'developer' when id_dev = 2 then 'publisher' end FROM developers WHERE id_dev in (1,2)
ifid_dev只能是其中之一1或2then 您可以完全删除该where子句。
1
2
where