typeorm 查询_Typeorm子查询添加选择

i'm new for using typeorm and this is the second time i'm confused with typeorm, i have the following query :

SELECT t1.a,t1.b,t2.a

(SELECT TOP 1 t1.a

FROM table1 t1

WHERE t1.b = t2.a

ORDER BY t1.a DESC

) AS MaxT1

FROM Table1 t1

INNER JOIN Table2 t2 ON t1.a = t2.a

i try this :

let query = await getManager()

.createQueryBuilder(Bid, 'bid')

.select([

'l.ID_anv_Lot',

'l.LotNumber',

'w.WineryName',

'bid.BidAmount',

'bid.ProxyBidAmount',

'er.ID_Contact'

])

.addSelect(Table1, t1)

.innerJoin(Lot, 'l', 'l.lotNumber = bid.lotNum AND l.paddleNumber = bid.paddleNumber')

but the result is all of rows on table1

解决方案

This Example may help you to perform sub query execution:

const posts = await connection.getRepository(Post)

.createQueryBuilder("post")

.where(qb => {

const subQuery = qb.subQuery()

.select("usr.name")

.from(User, "usr")

.where("usr.registered = :registered")

.getQuery();

return "post.title IN " + subQuery;

})

.setParameter("registered", true)

.orderBy("post.id")

.getMany();

Thank you

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值