django orm在两个带有子查询的列中

发布于 2025-02-03 18:29:31 字数 410 浏览 1 评论 0原文

想象我有两张桌子。一个人列出了客户拥有的许可证,每个许可都有特定版本和类型。另一表具有有关许可证(例如名称,价格,持续时间)的一般共享信息,也列出了类型和版本。

我需要查询信息表中是否与给定客户拥有的许可有关的任何行。在纯SQL中,可以使用此子查询来完成:

从版本_details中选择 *(版本,type)在(选择版本,从许可中键入company_id ='6f65e5cc-cd1f-4888888888888888888888888888236-38295bae393aa''); <<<<<<<<<<<<<<< /code>

有没有办法使用Django Orm来完成此操作?我知道如何使用子查询,但我不知道如何使用两列在其中做一个。

Imagine I have two tables. One lists licenses customers have, each with a specific version and type. The other table has general shared info about the licenses (eg name, price, duration), also listed by type and version.

I need to query the information table for any rows pertaining to licenses a given customer has. In pure SQL, that can be accomplished with this subquery:

select * from version_details where (version, type) in (select version, type from licenses where company_id = '6f65e5cc-cd1f-4888-a236-38295bae393a');

Is there a way to accomplish this with Django ORM? I know how to use a subquery but I can't figure out how to do a wherein with two columns.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情癖 2025-02-10 18:29:31
license = License.objects.get(company_id='6f65e5cc-cd1f-4888-a236-38295bae393a')
verson = VersionDetails.objects.filter(version=license.version, type=license.type)
license = License.objects.get(company_id='6f65e5cc-cd1f-4888-a236-38295bae393a')
verson = VersionDetails.objects.filter(version=license.version, type=license.type)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文