Counting number of grouped rows in mysql

后端 未结 5 738
有刺的猬
有刺的猬 2021-01-31 14:22

In a table xyz I have a row called components and a labref row which has labref number as shown here

Table xyz

labref             component
NDQA201303001         


        
5条回答
  •  萌比男神i
    2021-01-31 14:30

    Try this simple query without a sub-query:

    SELECT COUNT(DISTINCT component) AS TotalRows
    FROM xyz
    WHERE labref = 'NDQA201303001';
    

    See this SQLFiddle

提交回复
热议问题