select b.b_id from btable b inner join atable a on b.b_id = a_id
go
delete from btable where b_id in (...)
go
insert into btable select * from atable where a_id in (...)
go
The second and the third sql statement’s conditions are the first sql query result,
now I want to merge these three sql statement into single sql statement,
is there any way?
No, it’s not possible to do.
PS: having all the 3 clauses in one statement barely would be called “query optimization”. Optimization is when you improve a query performance, not when you just take N queries and get them in a single query.
Actually it’s a common misunderstanding among newbies – that the less queries automagically means they would perform faster. It’s just wrong. You should have as many queries as you need to retrieve all the necessary data – not less and not more.