Typeorm select max 与特定列 [英] Typeorm select max with specific column
本文介绍了Typeorm select max 与特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从表 quotation
中名为 quotationVersion
的表的列中选择最大值,
I want to select maximum value from a table's column named quotationVersion
from table quotation
,
getOneMaximumQuotationVersion() {
const query = this.createQueryBuilder("quotation");
query.select("MAX(quotation.quotationVersion)", "max");
// query.addSelect("MAX(quotation.quotationVersion)", "max");
return query.getOne();
}
推荐答案
如果要在选择子句中添加MAX、SUM等函数,需要做getRawOne() 或 getRawMany().这将为您提供原始响应:
If you want to add functions like MAX, SUM in the selection clause, you need to do getRawOne() or getRawMany(). This will give you the raw response:
getOneMaximumQuotationVersion() {
const query = this.createQueryBuilder("quotation");
query.select("MAX(quotation.quotationVersion)", "max");
// query.addSelect("MAX(quotation.quotationVersion)", "max");
return query.getRawOne();
}
这篇关于Typeorm select max 与特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文