[odb-users] Re: How to perform an aggregate subquery
MM
finjulhich at gmail.com
Mon Apr 8 21:40:57 EDT 2024
On Fri, 5 Apr 2024 at 13:41, Aldo Laiseca <alaiseca at gmail.com> wrote:
> Yes, actually I had figured out that a view was the approach to follow. I
> declared this:
>
> #pragma db view object(T1) object(T2)
> struct ViewT1T2 {
>
> #pragma db column("max(" + T1::timestamp_action + ")")
> #pragma db type("TIMESTAMP")
> boost::posix_time::ptime maxTimestamp;
> };
>
> However, after that, I don’t know how to recover the entire T1 object
> having the max value. Right now I solved my requirement in two steps:
>
> 1. Execute a query_value against the view to grab the maximum timestamp
> value.
> 2. Execute a query_one against the object T1 to get the row having the row
> matching the value obtained in step 1.
>
> Is there any way to do the above in one step? I read about object loading
> views; however, I don’t see how to include a max condition in a query in an
> object loading view.
>
> Thanks
>
>
I have the same question here
class B {
date begin;
date end;
};
class A {
std::vector<B> bs_;
};
both A and B are persistent.... B's table has object-id column pointed
to from A. and index column and value_* columns.
How to write the view to pick up the B row that matches the max index of
the vector?
Is the max() aggregation expressible neatly in a view?
Rds,
More information about the odb-users
mailing list