I would like to know how I can use a subquery in FROM clause using gorm. It would look like the following:
SELECT * FROM
(
SELECT foo.*
FROM foo
WHERE bar
You could use QueryExpr
, refer
http://jinzhu.me/gorm/crud.html#subquery
db.Where("amount > ?", DB.Table("orders").Select("AVG(amount)").Where("state = ?", "paid").QueryExpr()).Find(&orders)
Which generate SQL
SELECT * FROM "orders" WHERE "orders"."deleted_at" IS NULL AND (amount > (SELECT AVG(amount) FROM "orders" WHERE (state = 'paid')));