SQL Server specific query points, self-organizing

Source: Internet
Author: User
Tags time and date

1,distinctTo re-retrieve a column A worker's salary is greater than or equal to the warehouse number of any worker's salary in the WH1 warehouse .Select distinctCno fromZhigongbiaowhereGongzi>=(Select Min(Gongzi) fromZhigongbiaowhereCnoinch('WH1'))2,between    andin the ... To retrieve employees ' information in the range of 1220 to 1240 yuan. Select * fromZhigongbiaowhereGongzibetween 1220  and 12403,Order  by    desc,ASCsort a column in ascending or descending order by warehouse number, sort by payroll, and export all employee informationSelect* fromZhigongbiaoOrder  byCnoASC, Gongzidesc4,Join   ontable connection, indicating a horizontal table connection find work in a warehouse with an area greater than 400 and the city where these workers workSelectZnO, City fromCangkubiaoJoinZhigongbiao onCangkubiao.cno=Zhigongbiao. CNOwhereMianji> -5,Uniontable joins, representing portrait link tablesUnionAll Select lists in must have the same number of columns, similar data types and the same order in the result set as the column names from the first SELECT statement6, a related subquery that lists the order information for each employee with the highest total amount--key topics, related sub-queriesSelect* fromDingdanbiao AwhereDingdanzongjia not inch(Select MAX(Dingdanzongjia) fromDingdanbiao bwhereA.zno=B.zno)7, aggregate functionsCount,avg,sum,Max,min 8,Group  byGroup A column for development havingFurther screening on the basis of grouping, generally withGroup  byclause with the average wage of at least two employees per warehouseSelectCnoAVG(Gongzi) Average salary fromZhigongbiaoGroup  byCno having COUNT(*)>=19, subqueries (nested queries) use Query statements to query a column of data, and then use them as parameters in other query criteria to retrieve a warehouse number where the employee's salary is greater than or equal to the wages of all employees in the WH1 warehouse. SelectCno fromZhigongbiaowhereGongzi>=(Select Max(Gongzi) fromZhigongbiaowhereCnoinch('WH1'))Ten, time and date functionsDateDiffThe function is to get a value between two dates to query the name and age of each student in the student table. SelectSnameDATEDIFF( Year, Sbirthdy,getdate()) Age fromStudent Day(date), taking the day of the specified dateMonth(date), whichever month the date is set Year(date) The Sno, sname and Sbirthday columns of all students born in the same year were taken for the year of the date of the establishment and the student number is 3. --Key TopicsSelectSno,sname,sbirthdy fromStudentwhere  Year(Sbirthdy)=(Select  Year(Sbirthdy) fromStudentwhereSno='3') One,inch, like,=,>,<And so on, there areTopclause, query the first few lines for the student number and course number of the highest score in the score table. (sub-query or sort)SelectSno,cno fromScorewhereDegree=(Select MAX(degree) fromscore)Select Top 1*Sno,cno fromScoreOrder  byDegreedesc       

SQL Server specific query points, self-organizing

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.