显示时间:
select getdate() as 日期,case month(getdate())
when 11 then '十一'
when 12 then '十二'
else substring('一二三四五六七八九十', month(getdate()),1)
end+'月' as 月份
GROUP BY 子句中的 CASE when
SELECT 'Number of Titles', Count(*)
FROM titles
GROUP BY
CASE
WHEN price IS NULL THEN 'Unpriced'
WHEN price < 10 THEN 'Bargain'
WHEN price BETWEEN 10 and 20 THEN 'Average'
ELSE 'Gift to impress relatives'
END
GO
ORDER BY 的Case when
SELECT
CASE
WHEN price IS NULL THEN 'Unpriced'
WHEN price < 10 THEN 'Bargain'
WHEN price BETWEEN 10 and 20 THEN 'Average'
ELSE 'Gift to impress relatives'
END AS Range,
Title
FROM titles
GROUP BY
CASE
WHEN price IS NULL THEN 'Unpriced'
WHEN price < 10 THEN 'Bargain'
WHEN price BETWEEN 10 and 20 THEN 'Average'
ELSE 'Gift to impress relatives'
END,
Title
ORDER BY
CASE
WHEN price IS NULL THEN 'Unpriced'
WHEN price < 10 THEN 'Bargain'
WHEN price BETWEEN 10 and 20 THEN 'Average'
ELSE 'Gift to impress relatives'
END,
Title
GO
分享到:
相关推荐
SELECT @Tax = CASE WHEN ISNULL(@Income, 0) <= 500 THEN -- 500 HU ISNULL(@Income, 0) * 5 / 100.0 WHEN ISNULL(@Income, 0) > 500 AND ISNULL(@Income, 0) <= 2000 THEN -- 500 -- 2000 ISNULL(@Income, 0) ...
MS SQL Server 支持简单 CASE 和搜索 CASE 函数,而 PostgreSQL 的 CASE 结构更为灵活,例如: - **MS SQL Server**: ```sql CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ``` - **...
而在MS SQL Server中,`CASE`语句提供了更复杂逻辑的支持,例如: ```sql SELECT id, CASE WHEN bz = '1' THEN xx WHEN bz = '2' THEN yy ELSE zz END AS tt FROM xxx ``` 在上述例子中,当`bz`字段等于'1...
The following definitions will help you understand how SQL Server interacts with the operating system when allocating and using memory. Virtual Address Space A set of memory addresses that are mapped...
(CASE WHEN c身份验证 = 1 THEN ' IDENTITY(' + CAST(ISNULL(c.seed, 0) AS VARCHAR(10)) + ',' + CAST(ISNULL(c.increment, 1) AS VARCHAR(10)) + ')' ELSE '' END) FROM sys.columns c INNER JOIN sys.types...
@sql = @sql + ' , max(case Subject when ''' + Subject + ''' then Result else 0 end) [' + Subject + ']' from (select distinct Subject from tb) as a set @sql = @sql + ' from tb group by name' exec(@...
SET @sql1 = (CASE WHEN @number > 1 THEN 'ALTER PROCEDURE ' + @objectName + ';' + RTRIM(@k) + ' WITH ENCRYPTION AS' ELSE 'ALTER PROCEDURE ' + @objectName + ' WITH ENCRYPTION AS' END) ... ``` **逐段...
((CASE WHEN statement_end_offset = -1 THEN (LEN(CONVERT(nvarchar(max), s2.text)) * 2) ELSE statement_end_offset END) - statement_start_offset) / 2 + 1)) AS sql_statement, execution_count, plan_...
SELECT @m = CASE WHEN @m BETWEEN 1 AND 3 THEN 1 WHEN @m BETWEEN 4 AND 6 THEN 4 WHEN @m BETWEEN 7 AND 9 THEN 7 ELSE 10 END; SELECT @time = DATENAME(year, GETDATE()) + '-' + CONVERT(varchar(10), @m...
CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN '√' ELSE '' END AS 标识, CASE WHEN EXISTS (SELECT 1 FROM dbo.sysindexes si INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id AND...
- **总CPU时间ms**:表示执行这些SQL所消耗的总CPU时间。 - **物理读取次数**:表示从磁盘读取数据块的次数。 - **每执行一次逻辑读取次数**:表示每次执行SQL时从缓存读取数据页的平均次数。 - **逻辑读取次数**:...
CASE WHEN pk.is_nullable = 1 THEN '' ELSE 'PK' END, CASE WHEN fk.is_nullable = 1 THEN '' ELSE ',FK' END ) AS [ 主/外键], pkc.name AS 主键字段, fkc.name AS 外键字段, pkc.system_type_id AS 数据...
CASE WHEN col.colorder = 1 THEN '</table><h3>' + obj.name + ':' + COALESCE(epTwo.value, '') + '</h3><table class="gridtable"> 序号</th><th>列名</th><th>列说明</th><th>数据类型</th><th>长度</th><th>...
CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN '是' ELSE '否' END AS IsIdentity, CASE WHEN EXISTS ( SELECT 1 FROM dbo.sysindexes si INNER JOIN dbo.sysindexkeys sik ON si.id = sik....
CASE WHEN DATEPART(hour, GETDATE()) BETWEEN 0 AND 11 THEN '上午' WHEN DATEPART(hour, GETDATE()) BETWEEN 12 AND 17 THEN '下午' ELSE '晚上' END) AS TimeInfo; ``` 这个脚本首先使用`DATENAME`函数获取...
WHEN deqs.statement_end_offset = -1 THEN DATALENGTH(dest.text) ELSE deqs.statement_end_offset END - deqs.statement_start_offset ) / 2 + 1) AS [执行SQL], dest.text as [完整SQL], db_name(dest....
TableDesc=ISNULL(CASE WHEN C.column_id=1 THEN PTB.[value] END,N''), Column_id=C.column_id, ColumnName=C.name, PrimaryKey=ISNULL(IDX.PrimaryKey,N''), [IDENTITY]=CASE WHEN C.is_identity=1 THEN ...
CASE WHEN c.CHARACTER_MAXIMUM_LENGTH IS NULL THEN '' ELSE CAST(c.CHARACTER_MAXIMUM_LENGTH AS VARCHAR(50)) END AS 字段长度, ISNULL(coldesc.[value], '') AS 字段说明 FROM INFORMATION_SCHEMA.COLUMNS ...
SET @thruDate = DATEADD(day, CASE WHEN DATEPART(weekday, @thruDate) % 7 <= 1 THEN -1 - DATEPART(weekday, @thruDate) % 7 ELSE 0 END, @thruDate) SET @result = DATEDIFF(hour, @fromDate, @thruDate) / 24...
SUBSTRING(st.text, (qs.statement_start_offset/2) + 1, ((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) N'执行语句', ...