如何使用 Diesel ORM 获得最小值的行?我希望它生成一个看起来像这样的查询
SELECT tbl.*
FROM TableName tbl
INNER JOIN
(
SELECT Id, MIN(Point) MinPoint
FROM TableName
GROUP BY Id
) tbl1
ON tbl1.id = tbl.id
WHERE tbl1.MinPoint = tbl.Point
如何使用 Diesel ORM 获得最小值的行?我希望它生成一个看起来像这样的查询
SELECT tbl.*
FROM TableName tbl
INNER JOIN
(
SELECT Id, MIN(Point) MinPoint
FROM TableName
GROUP BY Id
) tbl1
ON tbl1.id = tbl.id
WHERE tbl1.MinPoint = tbl.Point
在不扩展柴油提供的 dsl 的情况下,只能通过sql_query
.
应用于此示例,这将导致以下查询:
sql_query("
SELECT tbl.*
FROM TableName tbl
INNER JOIN
(
SELECT Id, MIN(Point) MinPoint
FROM TableName
GROUP BY Id
) tbl1
ON tbl1.id = tbl.id
WHERE tbl1.MinPoint = tbl.Point
").load::<ResultType>(&conn)?
哪里ResultType
是实现的类型QueryableByName