SQL statement Query

Source: Internet
Author: User

Create Tableplayers (Playerno ID, namevarchar, SexChar,    JoinDate, townvarchar,)Create Tablepentity (IDint, Playerno, amount) grouped by player level and total statistics (total players)Select Count(*) as  Number     Case         whenJoined< 1980  Then ' Old'         whenJoined<=1983 1980  Then 'Youny'        Else 'OK' End  as  Level fromPlayersGroup  bylevels; When the gender is F, it is feman, otherwise man:Selectname, CaseSex when 'F'  Then 'Feman'Esle'Mans' End  asSex fromplayers; or forSelectname, Case     whenSex= 'F'  Then 'Feman'     whenSex= 'M'  Then 'Mans'    End  asSex fromplayers; According to the town, the player number is queried, and if the town is Stratford, when the year of accession is greater than 1980, as Young, when the year of entry is less than 1980, old, if the town is Elthon, the addition of the year is greater than 1980, expressed as'xxxx', otherwise the'yyyy'SelectPlayerno, Case Town when 'Stratford'  Then             Case                  when Join > 1980  Then Young when Join < 1980  Then OldEnd          when 'Elthon'  Then             Case                 when Join > 1980  Then 'xxxxx'                 when Join < 1980  Then 'yyyyy'            End        End  as Age fromplayers; Find the number and include the first letter and the dot in front of the name, and it is the player data ending with SSelectPlayerno,concat ( Left(Name,1),'.', name) asname fromPlayerswhere  Right(Name,1)= 's'find the number of each player who has at least two fines and not less than $25SelectPlayerno1 fromPlayers2whereAmount>  -          3Group  byPlayerno4  having Count(*)> 1        5Order  byPlayernoASC;6The order of execution is:2--3--4--5--6--1UnionUnion query Query captain number and fine squad numberSelectPlayerno fromPlayers1Union                          2SelectPlayerno fromPentity3The order of execution is1---3, then 2 merges 1,3 and duplicatesa player with a query number less than 10 and a maleSelect *  fromPlayerswherePlayerno< Ten  andSex= 'M'orSelect *  from(Select *  fromPlayers asPpwherePp.sex= 'M'there is an alias in the embedding method, and subsequent subqueries will have to use aliases to denote the height of nesting: numbers greater than 10 and less than 100, adding a time table greater than 1980 and a male player number1. number greater thanTen  Select *  fromPlayerswherePlayerno> Ten;2. Number less than -  Select *  fromPlayerswherePlayerno<  -;3. Join time is greater than1980  Select *  fromPlayerswhere Join > 1980;4. Sex is maleSelect *  fromPlayerswhereSex= 'M'The merger is:SelectPlayerno from(Select *              from(Select *                  from(Select *                          from(Select *  fromPlayerswhereSex= 'M') asMMwhereMm.Join > 1980) asJJwhereJj.playerno<  -) asPPwherePp.playerno> Ten) assearch for players with numbers 100 and the same players in the citySelect *  fromPlayerswherePlayers.sex=(SelectSex fromPlayerswherePlayerno=  -) Ane town=(SelectTown fromPlayerswherePlayerno=  -); or:Select *  from(Sex,town)=(SelectSex,town fromPlayerwherePlayerno=  -) Get the player's name and number in the same city as player number 27thSelectP1.playerno,p1.name fromPlayers p1,players P2whereP1.town=P2.town andP2.playerno=  - andP1.playerno<>  -available when the joined column name is the sameSelect *  fromPlayersJoinTeam onPlayers.playerno=Team.playerno orSelect * fromPlayersJoinTeam using (Playerno)

SQL statement Query

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.