1
누군가가 두 번째 쿼리와 동일한 결과를 반환하는 첫 번째 쿼리를 얻는 방법을 설명해 주시겠습니까? 첫 번째 쿼리는 카운트가 0 인 열에 대해 0 대신 1을 반환합니다. 두 번째 쿼리는 정상적으로 작동합니다. 나는 그것이 COUNT() 문장에 문제가 있다고 확신한다.Kohana DB 표현식이 올바른 결과를 반환하지 않습니다.
$lists = DB::select('favorites_lists.*', array(DB::expr('COUNT("favorites.list_id")'), 'total_favs'))
->from('favorites_lists')
->join('favorites', 'LEFT')
->on('favorites_lists.id', '=', 'favorites.list_id')
->where('favorites_lists.uid', '=', $user->id)
->group_by('favorites_lists.id')
->execute()
->as_array();
$lists = DB::query(
Database::SELECT,
'SELECT favorites_lists.*, COUNT(favorites.list_id) as total_favs
FROM favorites_lists
LEFT JOIN favorites
ON favorites_lists.id = favorites.list_id
WHERE favorites_lists.uid = ' . $user->id . '
GROUP BY favorites_lists.id'
)
->execute()
->as_array();
Kohana 문서가 보여주는 예입니다. 나는 원래 코드의 주석을 제거했으며 현재 작동 중이다. 어떤 변화가 있었는지 전혀 알지 못하지만 디버깅을하기 전에 데이터베이스에서 잘못된 결과가 나왔음을 보여주기 전에 잘 모르겠습니다. 귀하의 표현은 잘 작동하므로 계속해서 답변을 받아 들일 것입니다. 이 게시물이 Kohana의 불완전하고 혼란스러운 문서를 통해 걸어 가려는 사람들에게 도움이된다면, 결국 한 가지 괄호가 필요합니다. – Gavin