Transact-SQl语句简介

时间:2022-01-04 19:39:38

   1.Inserert  用于插入数据

    insert  into  tablename(id,name) value(1,'工资');

   2.update   用于修改数据

    update  tablename set ix_name='奖金',money=1000;

   3.delete

    delete from tablename where ix_id=1;

   4.select

    select * from tablename;

    如: 

     use FinanceDB;    //一个数据源名称

    select ix_data as 日期,ix_name as 类型名称, money as 金额 from tablename;

    where ix_data>'2009.3.29' and money >1000;

    5 ORDER BY

    select *from tablename order by TO_TIME,PERSONID desc;  //排序,首先根据io_time升序排列,相同的再按personid降序排列。

    6 统计函数count,max,min,GROUP BY,HAVING,连接查询,子查询和UNION联合。

    count

    select count(*) as 个数 from tablename where personid='sc001';//查询tablename中personid="sc001"的记录个数

    max, min

    use FinanceDB;

    select max(money) as 最大金额,min(money) as 最小金额 from tablename;

    sum,avg

     use FinanceDB;

    select sum(money) as 金额总计,avg(money) as 平均金额 from tablename;

      GROUP BY   子句分组查询 

    use FinanceDB;

    select ix_type,ix_name,sum(money) as 金额总计 from tablename group by ix_type,ix_name,order by ix_type,ix_name;

     HAVING