Group by, case then

Source: Internet
Author: User

In a query statement with a group by clause, the columns specified in the select list are either columns specified in the group by clause or contain clustering functions.
Select clientmediatypeid, count (ID) from Table group by table. clientmediatypeid having clientmediatypeid> 30

When having clause is used in the gropu by clause, only groups meeting having conditions are returned in the query results. A SQL statement can contain the WHERE clause and having clause. Having is similar to the WHERE clause and is used to set conditions.


Select Table. Field, (case when table. cityid <= 50 then 'No'
When table. cityid> = 50 then 'rows 'else' unclear 'end) 'Case column name' from hj_allnews

Select Table. Field, (Case table. Username when 'zhangshan'then' doesn't work'
When 'Lee 4' then' line 'else' unclear 'end) 'Case column name' from hj_allnews

When case then is used, if case is followed by the when field in the table and then the specific value of the field, there cannot be an arithmetic expression. Alas, this is a waste of such a conference .. Tom

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.