Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将where子句添加到此SQL语句_Sql - Fatal编程技术网

将where子句添加到此SQL语句

将where子句添加到此SQL语句,sql,Sql,本周早些时候我问了一个问题,我得到的答案是: select published, count(*) nbr from table1 group by published order by nbr desc limit 1 现在我想知道如何在语句中添加where子句,以便将得到的结果限制在不同类型的发布中。我的桌子看起来像这样: 身份证 类型 头衔 出版 where子句将位于type列上,例如wheretype=3。 提前谢谢 Dean是时候开始学习一些基本的SQL了,你不觉得吗?:) 当

本周早些时候我问了一个问题,我得到的答案是:

select published, count(*) nbr
from table1
group by published
order by nbr desc
limit 1
现在我想知道如何在语句中添加where子句,以便将得到的结果限制在不同类型的发布中。我的桌子看起来像这样:
  • 身份证
  • 类型
  • 头衔
  • 出版
  • where子句将位于type列上,例如where
    type=3

    提前谢谢

    Dean

    是时候开始学习一些基本的SQL了,你不觉得吗?:)


    当然,只需将
    WHERE
    语句添加到
    FROM
    语句之后,以及
    groupby
    语句之前。

    就基本规则而言,WHERE子句对每一行进行约束。行级约束首先创建一个进行分组的表。所以团队在哪里后面。若您想要组级约束,您可能会选择Having子句,但请记住一件事,您可以仅将Having约束应用于组中常见的项(在您的示例中,它是已发布的)

    select published, count(*) nbr    
    from table1
    where type = 3
    group by published
    order by nbr desc
    limit 1
    
    如前所述,您案例中的Where子句将放在“group by”之前和“from table1”之后

    select published, count(*) nbr    
    from table1
    where type = 3
    group by published
    order by nbr desc
    limit 1