[英]Get Count of Rows that is group by in sql
My sql query is getting data from sql table.here is my query 我的SQL查询正在从SQL表中获取数据。这是我的查询
SELECT * FROM `bookings` bo
LEFT JOIN routes ro ON bo.iRouteId = ro.iRouteId
LEFT JOIN buses bu ON bo.iBusId = bu.iBusId
WHERE eBookingBy = 'User' AND iUserId = '2'
ORDER BY bo.iBookingId DESC
Now this will return me o/p like this 现在,这将使我返回o / p
that means it returns me two data with having same booking id,now what i want is to do
GROUP BY bo.vBookingNo
Soo it wiill returns me only one data. 这意味着它将向我返回两个具有相同预订ID的数据,现在我要做的是
GROUP BY bo.vBookingNo
那么它只会向我返回一个数据。
Now what i need is i need an count of How many rows were group by . 现在我需要的是计数分组的行数。
For example if i use group by vBookingNo
in above query than it will o/p me only one result. 例如,如果我在上述查询中使用
vBookingNo
进行分组,则它将仅对我一个结果。 but it also returns me an count of rows that is group by. 但它也返回给我分组的行数。
so here it will return o/p Count 2. 因此在这里它将返回o / p Count 2。
Thanks. 谢谢。
you need count() 你需要count()
SELECT vBookingNo, count(*) FROM `bookings` bo
LEFT JOIN routes ro ON bo.iRouteId = ro.iRouteId
LEFT JOIN buses bu ON bo.iBusId = bu.iBusId
WHERE eBookingBy = 'User' AND iUserId = '2'
group by vBookingNo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.