To give a complete example, I need a little more detail on your queries.
There is no EXISTS operator in QCodo, so I don't think it can help you there. For IN, you can do:
QQ::In(QQN::Table1()->CategoryId, QQ::SubSql("select category_id from products where price < {1}", QQN::Table2()->Price);
Here is an example of defining a virtual attribute from Mike related to the examples database. It tells you how many projects each person is managing, and then sorts by that number.
$objPersonArray = Person::QueryArray(
QQ::All(), QQ::Clause(
QQ::Expand(QQ::Virtual('total_projects', QQ::SubSql('SELECT COUNT(id) FROM project WHERE project.manager_person_id={1}', QQN::Person()->Id))),
QQ::OrderBy(QQ::Virtual('total_projects'))
)
);
So the idea is that you can use QQ::Virtual() to define any sort of virtual attribute once. And then you can re-use that QQ::Virtual as often as you'd like. They can be used in sort clauses as well in DataGrids.
The QQ::SubSql allows you to define a sql subquery... but if you want to do things like compare it with items that are in the parent query, you'll need to use delimiters like {1}, {2}, {3}, etc. and then specify the QQNodes in the parent query you want to perform operations/comparisons on.
My own tests have shown that you can reuse a node delimiter, (i.e. {1}) multiple times in a query to refer to the same node.
To get the value of a virtual attribute, continue to use $obj->GetVirtualAttribute(“attr_name”);