SQL-Query-Fix
This commit is contained in:
@@ -18,13 +18,10 @@ Route::get('/', function()
|
|||||||
$news = News::aktuell()->get();
|
$news = News::aktuell()->get();
|
||||||
|
|
||||||
$topfilm = DB::table(DB::raw('film_films'))
|
$topfilm = DB::table(DB::raw('film_films'))
|
||||||
->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount'))
|
->select(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes,
|
||||||
->leftJoin('votes as film_u', function($join) {
|
COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
|
||||||
$join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE'));
|
COUNT(case when film_votes.stimme IS TRUE then 1 end) - COUNT(case when film_votes.stimme IS FALSE then 1 end) as vcount'))
|
||||||
})
|
->leftJoin('votes', 'votes.film', '=', 'films.id')
|
||||||
->leftJoin('votes as film_d', function($join) {
|
|
||||||
$join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE'));
|
|
||||||
})
|
|
||||||
->whereNull('films.gesehen')
|
->whereNull('films.gesehen')
|
||||||
->groupBy('id')
|
->groupBy('id')
|
||||||
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
||||||
@@ -153,13 +150,10 @@ Route::get('logout', array('as' => 'logout', function() {
|
|||||||
Route::get('vorgeschlagen', function() {
|
Route::get('vorgeschlagen', function() {
|
||||||
|
|
||||||
$filme = DB::table(DB::raw('film_films'))
|
$filme = DB::table(DB::raw('film_films'))
|
||||||
->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount'))
|
->select(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes,
|
||||||
->leftJoin('votes as film_u', function($join) {
|
COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
|
||||||
$join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE'));
|
COUNT(case when film_votes.stimme IS TRUE then 1 end) - COUNT(case when film_votes.stimme IS FALSE then 1 end) as vcount'))
|
||||||
})
|
->leftJoin('votes', 'votes.film', '=', 'films.id')
|
||||||
->leftJoin('votes as film_d', function($join) {
|
|
||||||
$join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE'));
|
|
||||||
})
|
|
||||||
->whereNull('films.gesehen')
|
->whereNull('films.gesehen')
|
||||||
->groupBy('id')
|
->groupBy('id')
|
||||||
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
||||||
|
|||||||
Reference in New Issue
Block a user