T-SQL basics SQL statement summary (1/6)

Source: Internet
Author: User

-- View all data in the student table
Select * from studio
-- Insert a new student information
Insert into studio (st_name, st_sex, st_age, st_add, st_tel) values ("Huang Lanqi", 13943943334, 'nanchong ', '123 ')
-- View all data of class
Select * from class
-- Add two pieces of data to the class table
Insert into class (cl_class, cl_coding, cl_o_time, cl_remark) values ('New electric training class', 'gxa-ncs-001 ', '2017-03-11', 'are good friends ')
Insert into class (cl_class, cl_coding, cl_o_time) values ('Aba normal training class', 'gxa-ABSZ-001 ', '2017-03-11 ')
-- Importance of updating a data condition
Update class set cl_remark = 'is really good' where cl_id = 5
-- Importance of deleting a data condition
Delete from class where cl_id = 7
-- Modify the column title
Select cl_id as 'class primary key', cl_class as 'class name' from class
Select name = st_name from studio
-- Use text strings
Select 'name: ', st_name from studio
-- ================== Query, add, delete, modify, ======================
-- Mainly involves or and not between in like ><=!> ! <! = <> () <=> = Is null is not null
-- Query all information with cl_id greater than 1
Select * from class where cl_id> 1
-- Use or
Select * from class where cl_id <> 10 or cl_class = 'baijie first class'
-- Use and
Select * from class where cl_id <> 10 and cl_class = 'baijie first class'
-- Use like and %
Select * from class where cl_class like 'baijie %'
Select * from class where cl_remark like '% am %'
-- Use
Select * from class where cl_id between 3 and 5
-- Use between with not
Select * from class where cl_id not between 3 and 5
-- Use is not null
Select * from class where cl_remark is not null
-- Use in
Select * from class where cl_class in ('first class of Qixing ', second class of 'baijie ')
-- ========================== Use mathematical operators ======================= ===
-- Mainly involves + = *
-- Query the number of weeks required for Java-related courses, which is calculated based on the number of 5 days per week and 6 courses per day.
Select 'Result '= co_num/5/6 from course where co_name in ('Java basics', 'Java project start ')
-- ============================== Use the aggregate function ========================= ======
-- COUNT SUM AVG MAX MIN
-- Query the total number of courses with less than 50 course hours
Select count (*) from course where co_num <50
-- Query the total number of lessons in all courses
Select sum (co_num) from course
-- Calculate the total course time fee. Assume 50 RMB for each course.
Select sum (co_num) * 50 from course
-- Query the courses with the least class hours
Select min (co_num) from course
-- Query the courses with the most class hours
Select max (co_num) from course
-- Query the average number of lessons per course
Select avg (co_num) from course

Home 1 2 3 4 5 6 Last page

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.