简体   繁体   English

SQL 查询使用计数和大于

[英]SQL query using count and greater than

I'm still learning.我还在学习。

How would I make this query work我将如何使这个查询工作


mysql> select publisher
    -> from books
    -> where count(publisher) > 3;

The syntax is not correct, but I want to know how to find the name of the publisher where the number of (times that publisher appears in my table) is greater than 3.语法不正确,但我想知道如何找到发布者的名称(该发布者在我的表中出现的次数)大于 3。

Thanks谢谢

You need to GROUP BY Publisher and a HAVING clause:您需要GROUP BY PublisherHAVING子句:

SELECT Publisher
FROM Books
GROUP BY Publisher
HAVING COUNT(*) > 3

This is TSQL but will probably give you what you need..这是 TSQL 但可能会给你你需要的东西..

SELECT Publisher, SUM(1) [Count]
FROM Books
GROUP BY Publisher
HAVING SUM(1) > 3

the most simple way to do it is using subquery:最简单的方法是使用子查询:

mysql> select publisher
-> from books
-> where 3 < (select count(publisher) from books);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM