CREATE TABLE Student1 (codeintprimary key,name varchar (Ten) unique,birthday datetime,sex varchar (5), Heightdecimal( -,0))Select* fromStudentinsert into student values (001,'to Aleees','male','1989/03/06',186)Select* fromstudentupdate StudentSetbirthday='1987/12/21', sex='male'whereName ='Dong Sheng'--Conditional query: Where filter:> < >= <=! =and orSelect* fromCarwhereoil<8and powers> the--Fuzzy query likeSelect* fromCarwhereName like'BMW 3 Series%'and price< $--SortSelect* fromcar Order by oil ASCSelect* fromcar order by oil descSelect* fromCarwhereName like'% BMW%'order by oil desc--Go heavySelectDistinct brand fromCar--GroupingSelectBrand fromCar GROUP BY BrandSelect*From car--aggregate function: AVG () Max () min () sum ()SelectAVG (Price) fromCarSelectAVG (Price) fromCarwhereName like'% BMW%'SelectMax (price) most expensive, min (price) lowest fromCarwhereName like'% BMW%'SelectCOUNT (*) fromCarwhereName like'% BMW%'SelectBrand,count (*), AVG (Price) fromCar GROUP BY Brand--Date-time functionsSelectSysdatetime ()--time of the systemSelectGETDATE ()--timestamp of database serviceSelectYear ('1999-09-23')SelectMONTH ('1999-09-23')SelectISDATE ('2015-06-30')SelectDATEADD (Week,5,)SelectDatename (DayOfYear,'2015-06-26')SelectDATEpart (Weekday,'2015-06-26')--String FunctionsSelectUpper (pic) from carSelectLTRIM ('123213')Select '12313'SelectLeft ('abcdef',3)SelectLEN ('AFDFASFD')SelectLOWER ('ACDFDD')SelectREPLACE ('ac123123123ac123123123','AC','haha')SelectREPLICATE ('ABC',Ten)SelectREVERSE ('ABC')SelectRight ('123123ADF',3)SelectSTR (1.567,3,2)SelectSUBSTRING ('ABCDEFG',2,3)--math function: ABS ceiling floor square sqrt round piSelectCode,name,ceiling (Price) fromCarSelect* fromCarwhereName like'% Audi%'and square (floor) >=2500--Conversion FunctionsSelectCode,name,'Fuel Consumption'+cast (oil asvarchar -)) fromCarSelectCode,name,'Fuel Consumption'+convert (varchar ( -), oil) fromCar
Sol function Primary query, de-weight, group, sort