zoukankan      html  css  js  c++  java
  • csdn里面的一个帖子关于sql

    --select   name   from   syscolumns   where   id=object_id( 'person')
    --創建測試環境
    Create   Table   TEST
    (学号   Varchar(20),
      姓名   Nvarchar(20),
      性别   Nvarchar(2),
      年龄   Int)
    --插入數據
    Insert   TEST   Select   '20040102 ', '龙波 ', '男 ',28
    Union   All   Select   '20040103 ','李霞 ', '女 ',22
    Union   All   Select   '20040104 ', '赵霞 ', '女 ',32
    Union   All   Select   '20040104 ', '赵霞 ', '女 ',32
    Union   All   Select   '20050201 ', '王温馨 ','女 ',31
    Union   All   Select   '20050201 ', '王温馨 ', '女 ',31
    Union   All   Select   '20050200 ', '王温馨 ', '女 ',32
    Union   All   Select   '20050200 ', '王温馨 ', '女 ',35
    GO
    --測試
    Select   Distinct   *   Into   #T   From   TEST
    Delete   A   From   #T   A   Where   Exists(Select   学号   From   TEST   Where   学号   =   A.学号   And   姓名   =   A.姓名   And   年龄   <   A.年龄)
    Delete   From   TEST
    Insert   TEST   Select   *   From   #T
    Drop   Table   #T
    Select   *   From   TEST   Order   By   学号
    GO
    --刪除測試環境
    Drop   Table   TEST
    --結果
    /*
    学号 姓名 性别 年龄
    20040102 龙波 男 28
    20040103 李霞 女 22
    20040104 赵霞 女 32
    20050200 王温馨 女 32
    20050201 王温馨 女 31
    */
  • 相关阅读:
    MongoDB知识
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    SQL Server 触发器
    TSQL游标使用
    python和C#的区别
    bcp和SqlDataAdapter进行批量跟新插入方法
    SQL Server中索引视图用法详解
    hdu 1950 Bridging signals
    UVA 116 Unidirectional TSP
    poj 3230 Travel
  • 原文地址:https://www.cnblogs.com/feng801/p/1315221.html
Copyright © 2011-2022 走看看