sql 两个字段相同的 显示其中一个字段!
比如:
id 调整日期 原来日期
001 2013-10-10 2013-10-11
002 2013-10-11 2013-10-11
003 2013-10-15 2013-10-15
004 2013-10-14 2013-10-15
我想要的效果为
id 调整日期 原来日期
001 2013-10-10 2013-10-11
002 2013-10-11
003 2013-10-15
004 2013-10-14 2013-10-15
就是说 调整日期中和原来日期相同的,就不显示调整日期了
求指教。。。。。。sql语句是不是要用 case when 怎么写呢?
[解决办法]
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-12-27 13:56:05
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
--Dec 28 2012 20:23:12
--Copyright (c) Microsoft Corporation
--Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] varchar(3),[调整日期] datetime,[原来日期] datetime)
insert [huang]
select '001','2013-10-10','2013-10-11' union all
select '002','2013-10-11','2013-10-11' union all
select '003','2013-10-15','2013-10-15' union all
select '004','2013-10-14','2013-10-15'
--------------开始查询--------------------------
select id,CASE WHEN [调整日期]=[原来日期] THEN NULL ELSE [调整日期] END [调整日期],[原来日期]
from [huang]
----------------结果----------------------------
/*
id 调整日期 原来日期
---- ----------------------- -----------------------
001 2013-10-10 00:00:00.000 2013-10-11 00:00:00.000
002 NULL 2013-10-11 00:00:00.000
003 NULL 2013-10-15 00:00:00.000
004 2013-10-14 00:00:00.000 2013-10-15 00:00:00.000
*/