Billpeng Space

技术源自生活
随笔 - 273, 文章 - 0, 评论 - 97, 阅读 - 60万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

随笔分类 -  SQL

摘要:delete WeiBoTopics where Id in(select max(Id) from WeiBoTopics group by WeiBoId,Title having COUNT(*) > 1); 阅读全文

posted @ 2015-04-20 15:38 billpeng 阅读(177) 评论(0) 推荐(0) 编辑

摘要:1.round() 函数是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位。 2.numeric 函数的2个参数,第一个表示数据长度,第二个参数表示小数点后位数。 例如: select cast(round(12.5,2) as numeric(5,2)) 结果:12.50 select cast(round(12.555,2) as numeric(5,2)) 结果:12.56 select cast(round(122.5255,2) as numeric(5,2))结果:122.53 select cast(round(1222... 阅读全文

posted @ 2012-08-27 15:37 billpeng 阅读(142503) 评论(0) 推荐(3) 编辑

摘要:alter table bbsmessage add quoteMessage varchar(2000) default '' 阅读全文

posted @ 2012-08-14 13:41 billpeng 阅读(305) 评论(0) 推荐(0) 编辑

摘要:select max(rowcnt) from sysindexes where id=object_id('foodstuff') 阅读全文

posted @ 2012-06-17 01:34 billpeng 阅读(186) 评论(0) 推荐(0) 编辑

摘要:select count(*) from (select GameScore.gameid from GameScore where GameScore.Username <> '' Group by GameScore.Username, GameScore.gameid) as a; 阅读全文

posted @ 2011-10-07 22:39 billpeng 阅读(1415) 评论(0) 推荐(0) 编辑

摘要:declare@viewnamevarchar(250),@idint,@textvarchar(8000)declare#aacursorforselectid,namefromsysobjectswhereobjectproperty(id,'IsView')=1anduid=1andleft(name,3)<>'sys'open#aafetchnextfrom#aainto@id,@viewnamewhile@@fetch_status=0beginselect@text=''select@text=@text+char(13) 阅读全文

posted @ 2011-04-02 09:21 billpeng 阅读(587) 评论(2) 推荐(0) 编辑

摘要:在.net中操作数据库的时候。 大家都喜欢用sqlparameter。 parameter是预编译的,可以加快速度,也可以防注入。 在使用mssql的时候用sqlparameter。 在使用mysql的时候使用mysqlparameters。 第一次使用mysql的时候,都经常犯一个错误 比如在使用mssql的时候,一条查询这么写 select name,id from user where id... 阅读全文

posted @ 2010-10-26 12:18 billpeng 阅读(418) 评论(0) 推荐(0) 编辑

摘要:[代码] 阅读全文

posted @ 2010-08-17 22:46 billpeng 阅读(682) 评论(0) 推荐(0) 编辑

摘要:select top 10 * from userinfo order by NEWID() 阅读全文

posted @ 2010-08-08 16:23 billpeng 阅读(303) 评论(0) 推荐(0) 编辑

摘要:http://database.ctocio.com.cn/tips/272/7588272.shtml 阅读全文

posted @ 2010-04-02 22:47 billpeng 阅读(234) 评论(0) 推荐(0) 编辑

摘要:如果我们想对一个表的每一行做出比较复杂的操作,大多会想到用游标,本文中,我们将换一种思路,用SQL Server 2005中的新函数ROW_NUMBER()和while循环来对每一行执行操作。详细的示例代码如下: select Department_No as departmentNo,ROW_NUMBER() OVER(ORDER BY Department_No) AS rowNumber i... 阅读全文

posted @ 2010-03-28 10:44 billpeng 阅读(239) 评论(0) 推荐(1) 编辑

摘要:select t.* from GameScore t where id in(select top 3 id from GameScore where GameID=t.GameID order by Score desc) order by Score desc 阅读全文

posted @ 2009-09-10 15:33 billpeng 阅读(1123) 评论(0) 推荐(0) 编辑

摘要:本周:select * from table where datediff(week,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段 本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0--C_CALLTIME 为日期字段 本季:select * from table where... 阅读全文

posted @ 2009-09-08 14:34 billpeng 阅读(203) 评论(0) 推荐(1) 编辑

摘要:一、查找重复记录1。查找全部重复记录Select * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)2。过滤重复记录(只显示一条)Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)注:此处显示ID最大一条记录二、删除重复记录1。删除全部重复记录(慎用)Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)> 阅读全文

posted @ 2009-06-24 10:34 billpeng 阅读(657) 评论(0) 推荐(0) 编辑

摘要:[代码] 阅读全文

posted @ 2009-05-21 14:15 billpeng 阅读(350) 评论(0) 推荐(0) 编辑

摘要:在SQL2000中,Select Top后是不能直接更变量的 阅读全文

posted @ 2009-02-25 12:00 billpeng 阅读(485) 评论(0) 推荐(0) 编辑

摘要:使用方法: select dbo.MD5('admin') as adminField 阅读全文

posted @ 2009-02-08 20:00 billpeng 阅读(515) 评论(0) 推荐(0) 编辑

摘要:Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->select * from UserInfo where DATEDIFF([year], Birthday, GETDATE()) >= 28--Birthday为数据库中的生日,28为年龄 阅读全文

posted @ 2009-02-01 19:18 billpeng 阅读(353) 评论(0) 推荐(0) 编辑

摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--DECLARE@tempFriendvarchar(5000)DECLARErsCURSORLOCALSCROLLFORselectFriendfromFriendwhereUsername=@UsernameOPENrsFETCHNEXTFROMrsINTO@tempFriend--循环WHILE@@FETCH_STATUS=0BEGINSET@Friend=@Friend+@tempFrien 阅读全文

posted @ 2009-01-28 23:31 billpeng 阅读(688) 评论(0) 推荐(0) 编辑

摘要:RETURN只能返回INT型,OUTPUT可以返回自定义类型 执行到RETURN的时候存储过程即结束。 而OUTPUT的变量可以重复设置 阅读全文

posted @ 2009-01-23 00:37 billpeng 阅读(1444) 评论(0) 推荐(1) 编辑

点击右上角即可分享
微信分享提示