我正在尝试编写等效的 SQL 查询:
SELECT tax.name as tax, SUM(item.cost * item.amount) as total FROM Invoices inv
JOIN InvoiceItems item ON( item.invoice = inv.id )
JOIN Taxes tax ON( tax.id = it.tax )
WHERE inv.id = 1
GROUP BY tax.id
我不知道如何在查询中“添加”总列,我的代码如下
val res = Invoices
.innerJoin(InvoiceItems, { Invoices.id }, { InvoiceItems.invoice })
.innerJoin(Taxes, { InvoiceItems.tax }, { Taxes.id })
.slice( Taxes.name.alias("tax"), InvoiceItems.cost, InvoiceItems.amount )
.select { Invoices.id eq 1 }
甚至可以这样做还是我必须稍后在代码中这样做?