在表xyz中,我有一个称为components的行和一个具有labref编号的labref行,如下所示
表xyz
labref component NDQA201303001 a NDQA201303001 a NDQA201303001 a NDQA201303001 a NDQA201303001 b NDQA201303001 b NDQA201303001 b NDQA201303001 b NDQA201303001 c NDQA201303001 c NDQA201303001 c NDQA201303001 c
我想对组件进行分组,然后计算返回的行数,该行等于3,我编写了以下SQL查询,但它无助于实现我的目标,而是为每个组件返回4
SELECT DISTINCT component, COUNT( component ) FROM `xyz` WHERE labref = 'NDQA201303001' GROUP BY component
查询返回
labref component COUNT(component) NDQA201303001 a 4 NDQA201303001 b 4 NDQA201303001 c 4
我现在想要实现的是,根据上述结果,对行进行计数,并将3作为行数返回,因此,可以采取任何解决方法
您需要做-
SELECT COUNT(*) FROM ( SELECT DISTINCT component FROM `multiple_sample_assay_abc` WHERE labref = 'NDQA201303001' ) AS DerivedTableAlias