SQL笔记1

来源:互联网 发布:java pdf ocr识别文字 编辑:程序博客网 时间:2024/05/29 01:53
 v如建一表:create table stuinfo(stuid int not null primary key,stuName varchar(50) not null,stuAge int not null ,stuSex varchar(4) not null);
插入几行数据:insert into stuinfo select 1,'小蔡',20,'男' Union select 2,'小刘',19,'女' Union select 3,'小张',20,'男' Union  select  4,'小蔡蔡',26,'女' Union select  5,'小蔡',20,'男'

现在执行SQL语句:

select * from stuinfo where  stuSex='女' and stuName like '%小蔡%' or stuName like '%小张%'
显示:3 小张 20 男
    4 小蔡蔡 26 女

select * from stuinfo where  stuSex='女' and (stuName like '%小蔡%' or stuName like '%小张%')
显示:4 小蔡蔡 26  女


时间比较:select * from idc_server where atterm_date>='2008-07-24'

时间类型注意单引号!!!!!!!!

查询格式化输出时间字段 :
select convert(varchar(10),Idc_Server.apply_date,120)as 申请时间 from idc_server
把多个字段查询出来以一列显示
select name+sex as studentinfo from stuinfo