SELECT u.*,(
SELECT COUNT(*) FROM (
SELECT id,author_id FROM posts p
UNION ALL
SELECT id, author_id FROM updates up
) total_table WHERE author_id = u.id) as total_post FROM users u ORDER BY total_post
我有查询行想要 DB::raw。你能帮助我吗???非常感谢
最佳答案
使用原始查询
,例如:
DB::select(DB::raw('SELECT u.*,(
SELECT COUNT(*) FROM (
SELECT id,author_id FROM posts p
UNION ALL
SELECT id, author_id FROM updates up
) total_table WHERE author_id = u.id) as total_post FROM users u ORDER BY total_post'));
关于php - 如何将查询语句转换为 DB::raw eloquent laravel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44587138/