<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: SQL Puzzle: SQL Advance Query &#8211; Place NULL for repeating values	</title>
	<atom:link href="https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 30 Oct 2019 09:40:06 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>
		By: koustav		</title>
		<link>https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/#comment-7860</link>

		<dc:creator><![CDATA[koustav]]></dc:creator>
		<pubDate>Wed, 30 Oct 2019 09:40:06 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5838#comment-7860</guid>

					<description><![CDATA[select
	case when rnk = 1 then A else NULL end as A
	,case when rnk = 1 then B else NULL end AS B
	,C
	,case when rnk = 1 then Code else NULL end AS Code from
(
select *, row_number()over (partition by Code,A,B order by A) as rnk from Code
) T1]]></description>
			<content:encoded><![CDATA[<p>select<br />
	case when rnk = 1 then A else NULL end as A<br />
	,case when rnk = 1 then B else NULL end AS B<br />
	,C<br />
	,case when rnk = 1 then Code else NULL end AS Code from<br />
(<br />
select *, row_number()over (partition by Code,A,B order by A) as rnk from Code<br />
) T1</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Phanindra Suripeddi		</title>
		<link>https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/#comment-7798</link>

		<dc:creator><![CDATA[Phanindra Suripeddi]]></dc:creator>
		<pubDate>Wed, 09 Oct 2019 18:15:19 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5838#comment-7798</guid>

					<description><![CDATA[DECLARE @Code TABLE 
(
	 A int
	,B Int
	,C int
	,Code CHAR(1) 	
)
 
INSERT INTO @Code
VALUES
 (1,1,1,&#039;A&#039;)
,(1,1,2,&#039;A&#039;)
,(1,1,3,&#039;A&#039;)
,(1,1,4,&#039;A&#039;)
,(2,2,1,&#039;C&#039;)
,(2,2,2,&#039;C&#039;)
,(2,2,3,&#039;C&#039;)

;With T As
(
	select *, checksum(concat(A,B,Code)) chksum From @code
)
,T2 as
(
	select *,lag(chksum) Over(partition by code Order by(select null)) as lag_chksum From T
) select 
 case When chksum = lag_chksum then NULL else A End as A
,case When chksum = lag_chksum then NULL else B End as B
,C
,case When chksum = lag_chksum then NULL else code End as code
From T2]]></description>
			<content:encoded><![CDATA[<p>DECLARE @Code TABLE<br />
(<br />
	 A int<br />
	,B Int<br />
	,C int<br />
	,Code CHAR(1)<br />
)</p>
<p>INSERT INTO @Code<br />
VALUES<br />
 (1,1,1,&#8217;A&#8217;)<br />
,(1,1,2,&#8217;A&#8217;)<br />
,(1,1,3,&#8217;A&#8217;)<br />
,(1,1,4,&#8217;A&#8217;)<br />
,(2,2,1,&#8217;C&#8217;)<br />
,(2,2,2,&#8217;C&#8217;)<br />
,(2,2,3,&#8217;C&#8217;)</p>
<p>;With T As<br />
(<br />
	select *, checksum(concat(A,B,Code)) chksum From @code<br />
)<br />
,T2 as<br />
(<br />
	select *,lag(chksum) Over(partition by code Order by(select null)) as lag_chksum From T<br />
) select<br />
 case When chksum = lag_chksum then NULL else A End as A<br />
,case When chksum = lag_chksum then NULL else B End as B<br />
,C<br />
,case When chksum = lag_chksum then NULL else code End as code<br />
From T2</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Nikhil Bhosale		</title>
		<link>https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/#comment-7667</link>

		<dc:creator><![CDATA[Nikhil Bhosale]]></dc:creator>
		<pubDate>Tue, 13 Aug 2019 05:26:29 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5838#comment-7667</guid>

					<description><![CDATA[Select 
(Case when C != &#039;1&#039; then NULL else A end) AS A,
(Case when C != &#039;1&#039; then NULL else B end) AS B,
C,
(Case when C != &#039;1&#039; then NULL else code end) AS code 
from  code]]></description>
			<content:encoded><![CDATA[<p>Select<br />
(Case when C != &#8216;1&#8217; then NULL else A end) AS A,<br />
(Case when C != &#8216;1&#8217; then NULL else B end) AS B,<br />
C,<br />
(Case when C != &#8216;1&#8217; then NULL else code end) AS code<br />
from  code</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Nilesh		</title>
		<link>https://www.dbrnd.com/2019/06/sql-puzzle-sql-advance-query-place-null-for-repeating-values/#comment-7468</link>

		<dc:creator><![CDATA[Nilesh]]></dc:creator>
		<pubDate>Sat, 06 Jul 2019 10:48:38 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5838#comment-7468</guid>

					<description><![CDATA[Select  
 Case When C = 1 then A Else NULL END as A,
 Case When C = 1 then B Else NULL END as B,
 C,
 Case When C = 1 then Code Else NULL END as Code
From Code]]></description>
			<content:encoded><![CDATA[<p>Select<br />
 Case When C = 1 then A Else NULL END as A,<br />
 Case When C = 1 then B Else NULL END as B,<br />
 C,<br />
 Case When C = 1 then Code Else NULL END as Code<br />
From Code</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
