Order a column conditional in SQL
来源:互联网 发布:陈建仁访问梵蒂冈'知乎 编辑:程序博客网 时间:2024/05/10 08:47
The below sample illustrates that we order Z descending if Zone is an even number, order Z ascending if Zone is an odd number.
declare @WhLocation table
(
LocationId int identity(1, 1),
Zone int,
Z varchar(20)
)
insert into @WhLocation values
(1, '2'),
(1, '3'),
(1, '1'),
(2, '1'),
(2, '3'),
(2, '2')
SELECT * FROM @WhLocation
ORDER BY
CASE WHEN Zone IS NOT NULL AND Zone%2=1 --odd number
THEN Z END ASC,
CASE WHEN (1=1)
THEN Z END DESC --NULL OR even number
- Order a column conditional in SQL
- Unkonw column 'xxx' in 'order clause'
- <Unknown column 'card_id' in 'order clause'>
- process a container in a reverse order
- 71.Which arithmetic operations can be performed on a column by using a SQL function that is built in
- conditional operator in Xcode
- How To Split column In SQL
- 【18】Sort a stack in ascending order
- Print A Tree In Vertical Order
- Output a string in reverse order
- PL/SQL Conditional Compilation
- A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column:
- MySQL How to add a column in a table?
- Traverse a binary tree in a level-based order
- Use Conditional attribute in C#
- Conditional Compilation In Java @ JDJ
- Integrity constraint violation: 1052 Column 'id' in order clause is ambiguou
- Yii报错:SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous
- 数据库中乐观锁与悲观锁的概念
- 改变dialog的位置
- mysql手册总结2
- c++ completion (vim)
- 数据库可疑处理
- Order a column conditional in SQL
- 组合和聚合
- JTable 获得选中行
- Java泛型
- vb.net读取任意xml文件
- PHP文件上传测试
- Add column to existing table with default value
- Locale,auto-rotate状态的获取
- WP-Super-Cache的使用