1

我有一个包含以下字段的表:id | 域名 | domain_certificate_no | 核心价值

select 语句的输出示例如下:

'57092', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_1', '55525772666'
'57093', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_2', '22225554186'
'57094', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_3', '22444356259'
'97168', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_1', '55525772666'
'97169', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_2', '22225554186'
'97170', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_3', '22444356259’

我想编写一个查询来检索重复的数量keyvalue,并且它与证书_1keyvalue的多个相关联。domain_certificate_no所以我写了这个:

select count(keyvalue), keyvalue from db.table group by (keyvalue) 
having count(keyvalue)>1 and domain_certificate_no like '%_1';

我收到一个错误号 1054 说 unknown column domain_certificate_no。你能告诉我有什么问题吗?如何编写查询以实现我的目的?

4

3 回答 3

1

只是关于逻辑:

SELECT COUNT(domain_certificate_no), keyvalue
FROM db.table 
WHERE domain_certificate_no LIKE '%_1'
GROUP BY keyvalue
HAVING COUNT(keyvalue)>1;

如果仍然存在未知列错误,请显示结果DESC db.table;

干杯。

于 2012-08-08T00:32:55.407 回答
1

LIKE关键字应该在您的WHERE子句中

   SELECT domain_certificate_no, COUNT(keyvalue) 
     FROM db.table 
    WHERE domain_certificate_no LIKE '%_1'
 GROUP BY domain_certificate_no
   HAVING COUNT(keyvalue) > 1;
于 2012-08-08T00:37:50.127 回答
0
SELECT
    COUNT(keyvalue) AS keyvaluecount, keyvalue 
FROM 
    db.table 
HAVING
    keyvaluecount > 1 AND domain_certificate_no LIKE '%_1' 
GROUP BY 
    (keyvalue)
于 2012-08-08T00:39:37.443 回答