Summary of where,having Filtration method

Source: Internet
Author: User

a where filter 1 Make with and and the OR Combining query Criteria

SELECT * from Sell WHERE sell_price>=1000 and (or) sell_price<=2000


2 To make use of. between and the Not between Filter Records

SELECT * from sell where sell_price between and a (notbetween is not in this range )


3. Use the inch and the not in Filter Records

SELECT * from the worker WHERE work_id in (' 9601 ', ' 9702 ') (not in is not this ...) Range


4 To make use of. like and wildcard filter Records

% has 0 or more characters-single character

[] Specify a range such as "a~f" [^] outside the specified range [^a~f]

? example, from "WORKER" find the name in the first two words is " ? text " staff information.

Select * from worker Where Work_name like ' _ text _ '

? Example: Query worker All employee information of Wang in the table

Select * FROM student Where student_name like ' Wang % '

? the employee information of duress surname Wang

Select * from the worker Where work_name like ' [ Liu Wang ]% '

? example, from "Worker" the lowest number of search job numbers in the table is not in 2~6 within the scope of the staff.

SELECT * from worker where work_id like '%[^2-6] '


5 To filter records with null values

SELECT * from supplier where Sup_tel are (not) null


Two having filter

Total number of employees with sales totals above $1000 and sales totals

Select Word_id,sum (sell_price) from sell where Sell_price > the group by word_id

Where filtering is the first to select the sales price above 1000, and then group the summary

Select Word_id,sun (sell_price) from sell GROUP by word_id have sum (sell_price) >1000

Having a filter is the first group summary, and then select the total sales of more than 1000


Different points:
1 WHERE Check that every record is full? having Check that the aggregated data for each group after the group rollup is full? sufficient conditions;
2 youcan use aggregate functions in the HAVING clause, but not in the whereclause.  


Where,having Filtering Method Summary

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.