java 22

SQL语句

  • 查询
    select ··
    from ··
    where··
    like··
    between ·· and ··
    as
  • 条件查询
    and=“并”集合
    or=“或”集合
    in=“在···范围内”
##根据课程代号(code)查找所有可选的课程设置        
 SELECT 
    co.id 'course_id',
    co.code 'course_code',
    co.name 'course_name',
    co.description 'course_description',
    co.credit 'course_credir',
    ct.id 'course_template_id',
    ct.course_type_id ,
    ct.create_datetime,
    cf.id 'course_offered_id',
    cf.class_capacity,
    cf.class_remain,
    cf.class_time
FROM
    course_template ct,
    course co,
    course_offered cf
WHERE
    cf.course_template_id = ct.id
        AND ct.course_id = co.id
        AND co.code = '数据库'
        and  cf.class_remain >0;
  • 插入语句
    Insert into table( ···)
    vlaues()
insert into student(id,firstname,lastname,phone,email,gender,age,student_status_id,accommodation_id,sid)values(2,'萧','燚','15705799575','[email protected]','男',19,1,2,102);
  • 更新语句
    update (table···)
    set ···
    where ···
    禁用安全更新
    set sql_safe_updates =0;
    开启安全更新
    set sql_safe_updates =1;
set sql_safe_updates=0;

UPDATE student 
SET 
    student_status_id = 1
WHERE
    gender = '男'; 

UPDATE teacher t 
SET 
    t.firstname = '栗子',
    t.lastname = '西'
WHERE
    t.id = 4;

set sql_safe_updates=1;
  • 排序
    order by (用于对结果排序)··· desc 降序
    order by (用于对结果排序)··· asc 升序
select* from  student order by  age asc;
select* from  student order by  sid desc;

你可能感兴趣的:(java 22)