避免针对内部使用的不同连接使用多个 ifexists,elseifexits 语句
插入具有不同场景的一张公用表中,
例如:
if exists(select id from tablename where id =1 )
insert into Temp
select * from tbl inner join ........
else if exists(select id from tablename where id=2)
insert into Temp
select * from tb2 inner join ........
else if exists(select id from tablename where id=3 )
insert into Temp
select * from tb3 inner join ........
....
就像使用 else 条件来连接不同 id 的不同表... 现在我想编写一个没有 else if,else if... 的单个查询,但是根据 id 值,应该调用相应的 select 语句
Inserting in one common table with the different scenarios
E.g:
if exists(select id from tablename where id =1 )
insert into Temp
select * from tbl inner join ........
else if exists(select id from tablename where id=2)
insert into Temp
select * from tb2 inner join ........
else if exists(select id from tablename where id=3 )
insert into Temp
select * from tb3 inner join ........
....
it is like using else condition for joining different tables for different id's...
now i want to write a single query without this else if,else if... but based on the id value the respective select statement should be called
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您希望使用 SELECT、WHERE 和 UNION ALL 定义查询(或视图)。有关详细信息,请参阅文档(postgreSQL、MySQL 或任何 SQL 方言)。
Perhaps you're looking to define a query (or view) using SELECT, WHERE, and UNION ALL. Consult the documentation (postgreSQL, MySQL, or whatever SQL dialect) for details.