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。你能帮助我吗???非常感谢
答案 0 :(得分:0)
使用raw query
之类的:
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'));
答案 1 :(得分:0)
或者您可以使用DB::satement
$query='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';
$data=DB::statement($query);
喜欢这个。