--simple crud for a single tableSelect * fromQ_user--Querying all ColumnsSelectUid,uname,upwd fromQ_user--Query The specified column can specify conditions with whereSelectUid* fromQ_userDeleteQ_user--all data for this table will be deleted (with caution) you can specify conditions with whereInsert intoQ_userValues('Zhang San','123','0','0','0',"')Insert intoQ_user (UNAME,UPWD)Values('John Doe','123')--insert must conform to the entity integrity of the subject (constraints ...)-----------------------------------------------------UpdateQ_userSetIsmorelogin='0', IsOnLine='1' --Change all columns to specify the condition with whereUpdateQ_userSetIsmorelogin='0', IsOnLine='1' whereUName='Zhang San'--Other Statements--1. DISTINCT (remove duplicate columns)SELECT DISTINCT * fromQ_user--2. WHERE clause--SELECT column name from table name WHERE column operator valueSelect * fromQ_userwhereUid> + andIsmorelogin!=1 --not equal to <>1 . and LEN(UName)between 2 and 5 --(Btetten A and B (including A and b)) andUName like '%1%' --Like fuzzy query--3. And and OR and is the set or Yes or setSelect * fromQ_userwhereIsOnLine='true' orIsOnLine='false'--4 Oreder By sort statement default is ascending ASC Descending descSelect * fromQ_userOrder byUiddesc--5 wildcard characters and like --wildcard characters --_ match with any single character --% matches a string that contains one or more characters --[] matches any single character in a specific range (for example, [a-f]) or a specific set (for example, [abcdef]). --[^] or [!] Matches any single character other than a specific range (for example, [^a-f]) or a specific set (for example, [^abcdef]). Select * fromQ_userwhereUName like '%1%'--contains 1Select * fromQ_userwhereUName like 'Li%'--start with LeeSelect * fromQ_userwhereUName like '% three' --End With three--the 6 in operator allows us to specify multiple values in the WHERE clause. (It's actually the same column or combination)Select * fromQ_userwhereIsOnLine not inch(0)--the operator after the where can be added not--7 alias asSelectB.freezetime,b.* fromQ_user asbSelectB.* from(Select * fromQ_user) bSelectUid asNumber, uName name, upwd password fromQ_user--8 Top Query (how many lines before query)--SQL AvailableSelect Top Ten * fromQ_userwhereUid not inch(Select Top TenUid fromQ_user)--query not the first 10 data (i.e. 20-30 data) in the first 10Select * fromQ_user--Aggregation Functions--avgSelect AVG(uId) asAverage fromQ_userSelect SUM(UID) asSum fromQ_userSelect COUNT(UID) asCount fromQ_userSelect Max(UID) asMaximum Value fromQ_userSelect min(UID) asMinimum value fromQ_user--The GROUP BY statement is used to combine aggregate functions to group result sets based on one or more columns. SelectBaid,COUNT(Baid),SUM(BID),AVG(BID) fromT_buyerGroup byBaid--conditions for having a group querySelectIsOnLine is online,COUNT(isOnLine) Number of people,AVG(uId) fromQ_userGroup byIsOnLine having COUNT(IsOnLine)>0 and 1=1
SQL Server Getting started with crud----tables