[英]Multiple update query with Multiple conditions
Basically I am facing an issue, both my queries are working fine, but instead of writing two queries, I want to write one query.基本上我面临一个问题,我的两个查询都工作正常,但我不想写两个查询,而是想写一个查询。 As you can see my table name is same just update the data on condition
如您所见,我的表名相同,只是根据条件更新数据
await getConnection()
.createQueryBuilder()
.update(StudentOrders)
.set({ OrderTypes: 'Fresh' })
.where({ allowRemote: true }).execute()
await getConnection()
.createQueryBuilder()
.update(StudentOrders)
.set({ OrderTypes: 'Old' })
.where({ allowRemote: false }).execute()
Although I can see what your obscurification language is doing, I am not sure how to translate SQL into it.虽然我可以看到你的模糊语言在做什么,但我不确定如何将 SQL 翻译成它。 However, you should easily enough.
但是,你应该足够容易。 In Postgres SQL you use the
case
expression for alternatives.在 Postgres SQL 中,您使用
case
表达式作为替代项。 So: (see demo )所以:(见演示)
update student_orders
set order_types = case when allow_remote
then 'Fresh'
else 'Old'
end ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.