如何构造子查询?

时间:2019-04-02 13:04:49

标签: rust-diesel

我正在尝试为此SQL语句建立查询:

SELECT * FROM operations
            WHERE action_type = 'Commit'
            AND block_number > (
                SELECT COALESCE(max(block_number), 0)  
                FROM operations 
                WHERE action_type = 'Verify'
            )

我的代码:

            use diesel::sql_types::{Nullable, Integer};
            sql_function!(coalesce, Coalesce, (x: Nullable<Integer>, y: Integer) -> Integer);    
            let ops: Vec<StoredOperation> = operations
            .filter(action_type.eq(ACTION_COMMIT)
                    .and(block_number.gt(
                        operations
                        .select(max(block_number))
                        .filter(action_type.eq(ACTION_VERIFY))
                        .single_value()
                    ))
            )
            .load(&self.conn)?;

无法编译。

0 个答案:

没有答案