中国网格虚拟主机不满意退款承诺!
24小时咨询热线:021-51095771  51087627
中国网格
快速建站 只选网格
域名+空间+数据库+维护 企业网站整体服务商
支付方式数 据 库优惠套餐
您当前的位置 
首页
快速建站
技术
MSSQL
正文

一些有用的sql语句实例

发布时间:2012-10-26 15:21:19| www.cnwg.cn | 文章标签:sql,语句

1Examples 

=======================================

select id,age,Fullname from tableOne a

where a.id!=(select max(id) from tableOne b where a.age=b.age and a.FullName=b.FullName)

=========================================

delete from dbo.Schedule where

RoomID=29 and StartTime>'2005-08-08' and EndTime<'2006-09-01' and Remark like 'preset' and UserID=107

and (

(ScheduleID>=3177 and ScheduleID<=3202 )

or (ScheduleID>=3229 and ScheduleID<=3254)

or (ScheduleID>=3307 and ScheduleID<=3332)

=========================================

delete tableOne

where tableOne.id!=(select max(id) from tableOne b where tableOne.age=b.age and tableOne.FullName=b.FullName);

==========================================

DataClient12/23/2005 5:03:38 PM

select top 5

DOC_MAIN.CURRENT_VERSION_NO as Version, DOC_MAIN.MODIFY_DATE as ModifyDT, DOC_MAIN.SUMMARY as Summary,

DOC_MAIN.AUTHOR_EMPLOYEE_NAME as AuthorName, DOC_MAIN.TITLE as Title, DOC_MAIN.DOCUMENT_ID as

DocumentID,Attribute.ATTRIBUTE_ID as AttributeId, Attribute.CATALOG_ID as CatalogId,DOC_STATISTIC.VISITE_TIMES as VisiteTimes,

DOC_STATISTIC.DOCUMENT_ID as DocumentID2

from DOC_MAIN DOC_MAIN

Inner join CATALOG_SELF_ATTRIBUTE Attribute on DOC_MAIN.CATALOG_ID=Attribute.CATALOG_ID

Left join DOC_STATISTIC DOC_STATISTIC on DOC_MAIN.DOCUMENT_ID=DOC_STATISTIC.DOCUMENT_ID

where (DOC_MAIN.AUTHOR_EMPLOYEE_ID = 1) and (Attribute.ATTRIBUTE_ID = 11)

order by VisiteTimes DESC

====================================

select top 1 DOCUMENT_ID,EMPLOYEE_NAME,COMMENT_DATE,COMMENT_VALUE

from dbo.DOC_COMMENT

where DOCUMENT_ID=19 and COMMENT_DATE = (select max(COMMENT_DATE) from DOC_COMMENT where DOCUMENT_ID=19)

====================================

select TITLE, (select top 1 EMPLOYEE_NAME

from dbo.DOC_COMMENT where DOCUMENT_ID=19) Commentman,

(select top 1 COMMENT_DATE

from dbo.DOC_COMMENT where DOCUMENT_ID=19) COMMENT_DATE

from DOC_MAIN where DOCUMENT_ID=19

======================================

alter view ExpertDocTopComment

as

selectDOCUMENT_ID, max(ORDER_NUMBER ) as lastednum

from dbo.DOC_COMMENT

group by DOCUMENT_ID

go

alter view ExpertDocView

as

select TITLE, a.AUTHOR_EMPLOYEE_ID , c.EMPLOYEE_NAME , c.COMMENT_DATE

from dbo.DOC_MAINa

left join

ExpertDocTopComment b

on

a.DOCUMENT_ID = b.DOCUMENT_ID  

inner join

DOC_COMMENT c

on

b.DOCUMENT_ID = c.DOCUMENT_ID and

b.lastednum = c. ORDER_NUMBER

======================================

select a.Id ,a.WindowsUsername ,

0 , 1 ,

a.Email ,

case b.EnFirstName when null then a.Username else b.EnFirstName end,

case b.EnLastName when null then a.Username else b.EnLastName end

from UUMS_KM.dbo.UUMS_User a

left join

UUMS_KM.dbo.HR_Employee b

on

a. HR_EmployeeId = b.id

=====================================

列出上传文档Z多的五个人的ID

select AUTHOR_EMPLOYEE_ID,count(AUTHOR_EMPLOYEE_ID)

from dbo.DOC_MAIN

group by AUTHOR_EMPLOYEE_ID

order by count(AUTHOR_EMPLOYEE_ID)

27192

69

1230

1116

列出上传文档Z多的五个人的信息

select distinct AUTHOR_EMPLOYEE_ID ,AUTHOR_EMPLOYEE_NAME

from dbo.DOC_MAIN

where AUTHOR_EMPLOYEE_ID

in (

select top 5 AUTHOR_EMPLOYEE_ID

from dbo.DOC_MAIN

group by AUTHOR_EMPLOYEE_ID

order by count(AUTHOR_EMPLOYEE_ID)

)

=================================


数据库空间

数据库存储空间

价格:200元/100M

MySql,SQL可选择

参考资料

我要评价

评价发表成功

错误提示
关于网格 | 联系方式 | 网站地图 | 客户中心 | 网格招聘 | 代理合作 | 支付方式 | 帮助中心
中国网格所属上海羽灿计算机科技有限公司版权所有 Copyright©cnwg.cn 2003-2013,All Rights Reserved.

联系电话:021-51095771 021-51087627 传真:021-51087637-202
版权所有:上海羽灿计算机科技有限公司 中国网格(cnwg.cn/cnwg.cc)©2003-2013 All Rights Reserved.
地址:上海市银都路3399弄533号 邮编:201108 ICP经营许可证编号:沪B2-20060019 沪ICP备06012189号

  • 经营性网站
    备案信息
  • 网络110
    报警服务
  • 文明办网
    先进单位
  • 支付宝
    特约商家
  • 网络社区
    征信网
  • 上海工商
    网上亮照