TypeORM QueryRunner 选择不同 [英] TypeORM QueryRunner Select distinct
问题描述
下面是我的 SQL 查询:
Below is my SQL query:
选择不同的ports.port_name from orders left join port_master onorders.officeId = ports.portId;
Select distinct ports.port_name from orders left join port_master on orders.officeId = ports.portId;
如何使用 typeorm 查询运行器编写上述 SQL 以选择不同的端口名称?以下语法获取所有端口
How to write above SQL using typeorm query runner to select the distinct port name? Below syntax fetches all the ports
await queryRunner.manager.find(Orders, {关系:[端口"],其中:过滤}).then((result: any) => {订单=结果;});
await queryRunner.manager.find(Orders, { relations: ["ports"], where: filter }).then((result: any) => { orders = result; });
推荐答案
另一种方法是使用查询构建器和 distinct
方法
Another way to do this is by using the query builder and distinct
method
await this.createQueryBuilder('entity name')
.select('column')
.distinct(true)
.getRawMany();
这篇关于TypeORM QueryRunner 选择不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!