天天看点

模糊查询和子查询笔记(2009

  (1)模糊查询:

select * from    customers

where customername like 'a_% '

@.针对的是字符串 ''

@.必须使用like

@.通配符 % 、_ 、[]-->指其中的任一个字符

    [abc]-->指abc中的任一个字母

    [a-k]-->指a到k里的任一个字母

    [^a-k]-->指除a-k外的任一个字母

(2)子查询    可放在select和where中...

例:判断是否有相同的学号:

select count(*) ,xh from student

group by xh

having count(*)>1 or count(3)=2

@按子查询返回的结果分类------对应的方法

                A口(一行一列)---- 直接取值

                B目(多行一列)---- 比较列清单 in、>all、<all、>any、<any

                C田(多行多列)----- 测试存在 exist()逻辑函数 返回的一个值true/false

    >all ==>大于后面表的最大值

    <all ==>小于后面表的最小值

    >any ==>大于后面表的最小值

    <any ==>小于后面表的最大值

@把查询的数据插入到一张新表中

select * into newtable from table1

@把数据写到存在的表中

insert into table1 select * from    table2

@创建表结构

select * into table1 from    table2 where 1=2