<?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: How to find the longest common substring pattern in different group of strings in SQL</title>
	<atom:link href="http://oraqa.com/2007/08/14/how-to-find-the-longest-common-substring-pattern-in-different-group-of-strings-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2007/08/14/how-to-find-the-longest-common-substring-pattern-in-different-group-of-strings-in-sql/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Tue, 06 Jul 2010 14:28:12 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: newkid</title>
		<link>http://oraqa.com/2007/08/14/how-to-find-the-longest-common-substring-pattern-in-different-group-of-strings-in-sql/comment-page-1/#comment-292</link>
		<dc:creator>newkid</dc:creator>
		<pubDate>Thu, 01 Jul 2010 20:31:05 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/08/14/how-to-find-the-longest-common-substring-pattern-in-different-group-of-strings-in-sql/#comment-292</guid>
		<description>The difference is, first I find all common characters, then use them to build common sub strings. 
&lt;PRE&gt;
SELECT id,grp_id,in_str,w
  FROM (SELECT t.*,rank() OVER(PARTITION BY grp_id ORDER BY LENGTH(w) DESC) rnk
          FROM (SELECT t.*,COUNT(DISTINCT id) OVER(PARTITION BY grp_id,w) cnt_w 
                  FROM (SELECT t.*,REPLACE(SYS_CONNECT_BY_PATH(c,&#039;/&#039;),&#039;/&#039;) w
                         FROM (SELECT * 
                                 FROM (SELECT t.*,COUNT(DISTINCT id) OVER(PARTITION BY grp_id,c) cnt_c
                                         FROM (SELECT t.*,rn,SUBSTR(in_str,rn,1) c
                                                FROM (SELECT t8.*,COUNT(*) OVER (PARTITION BY grp_id) cnt FROM t8) t
                                                    ,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM&lt;=100)
                                              ) t
                                       WHERE c IS NOT NULL
                                       )
                               WHERE cnt=cnt_c
                               ) t
                       CONNECT BY id=PRIOR id AND rn = PRIOR rn +1
                       ) t
                ) t
        WHERE cnt = cnt_w
        )
WHERE rnk=1;
&lt;/PRE&gt;</description>
		<content:encoded><![CDATA[<p>The difference is, first I find all common characters, then use them to build common sub strings. </p>
<pre>
SELECT id,grp_id,in_str,w
  FROM (SELECT t.*,rank() OVER(PARTITION BY grp_id ORDER BY LENGTH(w) DESC) rnk
          FROM (SELECT t.*,COUNT(DISTINCT id) OVER(PARTITION BY grp_id,w) cnt_w
                  FROM (SELECT t.*,REPLACE(SYS_CONNECT_BY_PATH(c,&#8217;/'),&#8217;/') w
                         FROM (SELECT *
                                 FROM (SELECT t.*,COUNT(DISTINCT id) OVER(PARTITION BY grp_id,c) cnt_c
                                         FROM (SELECT t.*,rn,SUBSTR(in_str,rn,1) c
                                                FROM (SELECT t8.*,COUNT(*) OVER (PARTITION BY grp_id) cnt FROM t8) t
                                                    ,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM&lt;=100)
                                              ) t
                                       WHERE c IS NOT NULL
                                       )
                               WHERE cnt=cnt_c
                               ) t
                       CONNECT BY id=PRIOR id AND rn = PRIOR rn +1
                       ) t
                ) t
        WHERE cnt = cnt_w
        )
WHERE rnk=1;
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
