各种基本之语句:
create database temp1
create table temp2(表格名 nvarchar(50) not null)
insert into temp2 values(999)
select * from temp2
insert Customer(loginID, password, name, address, phone)
values(103, 123, '王五','湖南长沙',120)
insert into Products values('电饭煲', '1', '5.5', '非常好用的煮饭工具', 100, '2020/4/14')
insert Customer(loginID, password, name, address, phone)
select 103, 123, '生七','湖南长沙',121
union
select 104, 123, '赵六','湖南郴州',119
update employee set address = '美国'
update employee set salary = 10000+100 where name = '阿六'
delete from customer where loginID = 102
delete from customer
drop table OrderCopy
select * into OrderCopy from Customer
select * from employee where name = '阿六'
select name from employee
select * from [Order]
select name 姓名, salary 加薪前的工资, salary*2 加薪后的工资 from employee
select name 姓名, price 价格 from [order]
select distinct birthday 生日,name 姓名 from employee
各种基本之函数:
create table temp(数字 int not null)
insert into temp values(100)
select * from temp
drop table temp
select num 数字, num+1 加法, num%10 模10 from temp
select * from Customer where name != '李一'
select * from Customer where name != '李一' and address = '江西'
select name 姓名, loginId 账号, password 密码, address 地址, phone 电话
from customer order by loginId desc, phone
select * from customer
select top 3 * from customer order by phone
select top 3 percent * from customer order by phone
select name 姓名, address 地址, phone 电话 from Customer where
name like '张%'
select name 姓名, address 地址, phone 电话 from Customer where
name like '%三'
select name 姓名, address 地址, phone 电话 from Customer where
name like '张_'
select name 姓名, address 地址, phone 电话 from Customer where
name like '[张]三'
select * from customer where address in('湖南永州')
select * from customer where address = '北京' or address = '上海'
select * from customer where customerid between 10 and 30
select replace('ming','ing','i') 替换后的结果
select reverse('ming')
select str('1212.322')
select substring('超神学院',1,2)
select name 姓名, substring(name,2,1) 截取后 from customer
select getDate()
select day(getdate()) 天, month(getdate()) 月, year(getdate()) 年
select datediff(day,getdate(),'2021/4/13') 天数,
datediff(month,getdate(),'2021/4/13') 月数,
datediff(year,getdate(),'2021/4/13') 年数
select dateadd(day, 1, getdate()) 一天后,
dateadd(month, 1, getdate()) 一月后,
dateadd(year, 1, getdate()) 一年后
select datename(weekday, getdate())
select power(2,2) '2的2次方', power(2,3) '2的3次方'
select round(122.23232,2)
select round(rand(),1)*10 '转化为0~10之间的随机数'
select cast('mingright' as varchar(2)) cast结果
select convert(nvarchar(30),getdate(),130) convert结果
其中convert可以选择的样式有,如下表所示:
聚合函数:
select sum(salary) 全体员工工资总和 from employee
select min(salary) 最高工资 from employee
select max(salary) 最高工资 from employee
select avg(salary) 最高工资 from employee
select count(*) 员工人数 from employee
select count(birthday) 有出生记录的员工人数 from employee