需求1:vehicle表统计车组group下的车辆vehicle数量
SQL语句:SELECT groupId,COUNT(*) FROM vehicle GROUP BY groupId
需求2:vehicle表统计车组group下的车辆vehicle数量,并按照车辆数量降序排序
SQL语句:SELECT groupId,COUNT(*) AS vehicle_number FROM vehicle GROUP BY groupId ORDER BY vehicle_number DESC
需求3:vehicle表下统计车组group下的车辆vehicle数量,并按照车辆数量降序排序,同时查找vehicle_group表把groupId转换成车组名字
SQL语句:
SELECT
v.groupId,
vg.groupName,
COUNT(*) AS vehicle_number
FROM
vehicle v