使用laravel5.6和mysql。我有下表中的车辆名称
id name number type
1 def 123 Car
2 lki 589 Van
3 loi 256 Truck
4 oiu 569 Car
5 hyy 589 Van
现在我需要计算每种类型的列数,我不想循环计算。我只需要数一数每种类型,并显示在刀片文件。这样地,
Car 2
Van 2
Truck 1
等。。你怎么能这么做?
3条答案
按热度按时间hsvhsicv1#
你只需要
Group By
上type
列,并使用Count(*)
要计算行数:gc0ot86w2#
只是使用
DB
门面与groupby一起计数ev7lccsx3#
这应该管用
有关“分组方式”和“计数”的详细信息,请参阅本教程。高级查询