Getting the number of rows with a GROUP BY query

后端 未结 5 1162

I have a query to the effect of

SELECT t3.id, a,bunch,of,other,stuff FROM t1, t2, t3 
WHERE (associate t1,t2, and t3 with each other) 
GROUP BY t3.id 
LIMIT          


        
5条回答
  •  猫巷女王i
    2020-12-12 16:40

    Are the "bunch of other stuff" all aggregates? I'm assuming so since your GROUP BY only has t3.id. If that's the case then this should work:

    SELECT
         COUNT(DISTINCT t3.id)
    FROM...
    

    The other option of course is:

    SELECT
         COUNT(*)
    FROM
         (
         
         ) AS SQ
    

    I don't use MySQL, so I don't know if these queries will work there or not.

提交回复
热议问题