SQL常用命令

    xiaoxiao2021-03-25  138

    1:创建数据库 create datebase dbtest;

    2:创建表 create table tabletest( id char(10) , name varchar2(100) not null, constraint pk_primary primary key(id,name) );

    3:查询语句 1)全部查询

    select * from tabletest

    2)跨表查询并排序

    select a.*,b.* from tabletest a left join tabletest1 b on a.id = b.id where b.name = '张三' order by a.id desc,b.id asc

    3)查询相同及like 通配符

    select distinct id,name from tabletest where id in ('1','2') or name like '%a%' or name like 'a_b_c' or name like '[!abc]';

    4)平均数,总数,个数等查询

    select avg(id) from tabletest; select sum(name) from tabletest; select count(*) from tabletest; select first(id) from tabletest; select last(name) from tabletest; select top 2 id from tabletest; select max(id),min(name) from tabletest;

    4:插入语句

    insert into tabletest (id,name) values('11','220');

    5:更新语句

    update tabletest set id = '22' ,name = '11' where id = '1';
    转载请注明原文地址: https://ju.6miu.com/read-6298.html

    最新回复(0)