几个sql语句

1、查找数据库中用到表tb_blackname的表、存储过程等:         select a.text,b.name,b.xtype from dbo.syscomments a,dbo.sysobjects b         where a.id=b.id and PATINDEX('%tb_blackname%', a.text)>0         order by xtype

2、对某个字段按区间统计条数 select case when buildfeecountructfee<1000 then '0-1000'               when         buildfeecountructfee>=1000 and buildfeecountructfee <5000 then '1000-5000'               when         buildfeecountructfee>=5000 and buildfeecountructfee <10000 then '5000-10000'                 else '10000以上'           end,count(*) from tb_buildfee group by case when buildfeecountructfee<1000 then '0-1000'               when         buildfeecountructfee>=1000 and buildfeecountructfee <5000 then '1000-5000'               when         buildfeecountructfee>=5000 and buildfeecountructfee <10000 then '5000-10000'                 else '10000以上'           end 3、对某个时间字段,按周期统计 --周期(年) select devicename,year(DeviceFinishDate),count(*) from tb_device group by devicename, year(DeviceFinishDate) --周期(年、月) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),month(DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),month(DeviceFinishDate)) --周期(年、季度) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(qq,DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(qq,DeviceFinishDate)) --周期(年、周) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(wk,DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(wk,DeviceFinishDate))

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值