Counting number of grouped rows in mysql

后端 未结 5 731
有刺的猬
有刺的猬 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条回答
  •  自闭症患者
    2021-01-31 14:22

    You need to do -

    SELECT
        COUNT(*)
    FROM
        (
            SELECT
                DISTINCT component
            FROM
                `multiple_sample_assay_abc`
            WHERE
                labref = 'NDQA201303001'
        ) AS DerivedTableAlias
    

    You can also avoid subquery as suggested by @hims056 here

提交回复
热议问题