代码如下 select distinct G.* ,(select BUSINESS_NAME from BusinessInfo where BusinessInfo.BUSINESS_BID=G.G_BUSINESS_ID) as BUSINESS_NAME ,(select sum(StockGNum) from StockDetail where StockDetail.StockGID =G.G_ID) as StockGNum ,(select sum(StockRemovalGNu
SELECT DB_NAME(database_id) AS [Database Name],[Name] AS [Logical Name],[Physical_Name] AS [Physical Name],((size * 8) / 1024/1024) AS [Size(GB)],[differential_base_time] AS [Differential Base Time] FROM sys.master_files 1.查询各个磁盘分区的剩余空间: Exec master.
原文:sql server 查询本年的每个月的数据 一.以一行数据的形式,显示本年的12月的数据,本示例以2017年为例,根据CreateDate字段判断,计算总和,查询语句如下: select sum(case when datepart(month,CreateDate)=1 then 1 else 0 end) as '1月', sum(case when datepart(month,CreateDate)=2 then 1 else 0 end) as '2月', sum(case w
SQL SERVER 查询第20行到30之间的数据 1.先查询前20行的ID,后查询除去20条记录的前10条记录 SELECT TOP 10 * FROM tbBank WHERE BankID NOT IN(SELECT TOP 20 BankID FROM tbBank ORDER BY BankID ASC) 2.先查询前20行记录最大的ID,后查询大于该值的前10条记录 SELECT TOP 10 * FROM tbBank WHERE BankID>(SELECT MAX(BankID
处理百万级以上的数据提高查询速度的方法: 1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 3.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is null 可以在num上设置默认值0,确保表中num列没有