我想显示最少借贷的贷款。在这种情况下,两个贷款与最少数量的借款人相关联。
student
这应该产生car
和{{1}}但是现在它只给我一个。我应该如何修改我的查询来解决这个问题?
答案 0 :(得分:3)
以下是使用CTE的方法:
<aside class="sidebar">
{% if auth %}
<article>
<h2>Hello, {{ auth.getFirstNameOrUsername }}!</h2>
<h2><a href="{{ urlFor('logout') }}">Logout</a></h2>
</article>
{% else %}
<article>
<h2>Welcome!</h2>
<div class="registerorlogin"><h2><a href="{{ urlFor('register') }}">Register</a></h2>
<h3 class="center">or</h3>
<h2><a href="{{ urlFor('login') }}">Login</a></h2></div>
</article>
{% endif %}
{% if auth.perm_one %}
<article>
<h2>Test</h2>
</article>
{% endif %}
{% if auth.perm_two %}
<h2>TEST 2</h2>
{% endif %}
</aside>
注意:
'subcategory' => [
'title' => 'Category tree',
'type' => 'relationship',
'name_field' => 'tree',
'options_filter' => function($query) {
$str = 'select CONCAT(cat.name, " » ", sc.name) as tree,
cat.id, cat.name, sc.id, sc.name
from categories cat
inner join subcategories sc on sc.category_id = cat.id';
$query = \DB::table('subsubcategories')->select(\DB::raw($str));
return $query;
}
],
考虑没有借款人的贷款类型。WITH lb as (
SELECT l.type, COUNT(b.num) as cnt
FROM loan l LEFT JOIN
borrower b
ON l.no = b.num
GROUP BY l.type
)
SELECT lb.type
FROM lb
WHERE lb.cnt = (SELECT MIN(lb.cnt) FROM lb);
语法。简单的规则:从不在LEFT JOIN
子句中使用逗号;始终使用明确的JOIN
语法。