Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ÏÈɸѡÔÚ¹ØÁªµÄÀý×Ó

select ID,Item1,Item2,Item3,Item4
into #Temp
from (
select ID='200910',Item1='A',Item2='B',Item3='C',Item4='T1'
union all
select ID='200910',Item1='',Item2='B',Item3='C' ,Item4='G2'
union all
select ID='200910',Item1='A',Item2='D',Item3='C' ,Item4='T3'
union all
select ID='200910',Item1='A',Item2='F',Item3='C' ,Item4='H4'
union all
select ID='200911',Item1='A',Item2='D',Item3='C' ,Item4='T5'
union all
select ID='200911',Item1='A',Item2='',Item3='E' ,Item4='T6'
union all
select ID='200911',Item1='',Item2='',Item3='C' ,Item4='T7'
) Tab
SELECT A.*
into #T1
from #Temp AS A
   LEFT JOIN #Temp AS B
ON A.ID = B.ID
    AND CASE WHEN ISNULL(NULLIF(A.Item1,''),'') = '' THEN 1 ELSE 0 END
      + CASE WHEN ISNULL(NULLIF(A.Item2,''),'') = '' THEN 1 ELSE 0 END
      + CASE WHEN ISNULL(NULLIF(A.Item3,''),'') = '' THEN 1 ELSE 0 END
    < CASE WHEN ISNULL(NULLIF(B.Item1,''),'') = '' THEN 1 ELSE 0 END
      + CASE WHEN ISNULL(NULLIF(B.Item2,''),'') = '' THEN 1 ELSE 0 END
      + CASE WHEN ISNULL(NULLIF(B.Item3,''),'') = '' THEN 1 ELSE 0 END
    AND ISNULL(NULLIF(B.Item1,''),A.Item1) = A.Item1
    AND ISNULL(NULLIF(B.Item2,''),A.Item2) = A.Item2
    AND ISNULL(NULLIF(B.Item3,''),A.Item3) = A.Item3
WHERE B.ID IS NULL
select ID,Item1,Item2,Item3
into #T2
from (
select ID='200910',Item1='A',Item2='',Item3='C'
union all
select ID='200910',Item1='A',Item2='D',Item3='C'
union all
select ID='200911',Item1='A',Item2='H',Item3='C'
union all
select ID='200911',Item1='',Item2='',Item3='C'
) Tab
select * from #Temp
select * from #T1
select * from #T2
select A.*,B.* from #T2 A
left join #T1 B
ON A.ID=B.ID
AND ISNULL(NULLIF(B.Item1,''),A.Item1) = A.Item1
    AND ISNULL(NULLIF(B.Item2,''),A.Item2) = A.Item2
    AND


Ïà¹ØÎĵµ£º

ÕÒµ½ÒýÆð´ÅÅÌÅÅÐòµÄSQL

ÏÂÃæµÄÕâЩ½Å±¾¶¼¿ÉÒÔÕÒµ½ÒýÆð´ÅÅÌÅÅÐòµÄSQL¡£ 
SELECT /*+ rule */ DISTINCT a.SID, a.process, a.serial#,
TO_CHAR (a.logon_time, 'YYYYMMDD HH24:MI:SS') LOGON, a.osuser,TABLESPACE, b.sql_text
from v$session a, v$sql b, v$sort_usage c
WHERE a.sql_address = b.address AND a.saddr = c.session_addr; ......

Ô¤·ÀSQL×¢Èë¹¥»÷Ö®ÎÒ¼û

1¡¢ SQL×¢Èë¹¥»÷µÄ±¾ÖÊ£ºÈÿͻ§¶Ë´«µÝ¹ýÈ¥µÄ×Ö·û´®±ä³ÉSQLÓï¾ä£¬¶øÇÒÄܹ»±»Ö´ÐС£
2¡¢ Ã¿¸ö³ÌÐòÔ±¶¼±ØÐë¼ç¸ºÆð·ÀÖ¹SQL×¢Èë¹¥»÷µÄÔðÈΡ£
¡¡¡¡ËµÆð·ÀÖ¹SQL×¢Èë¹¥»÷£¬¸Ð¾õºÜÓôÃÆ£¬Õâô¶àÄêÁË´ó¼ÒÒ»Ö±ÔÚÌÖÂÛ£¬Ò²Ò»Ö±ÔÚÕùÂÛ£¬¿ÉÊǵ½ÁËÏÖÔÚËƺõ»¹ÊÇûÓж¨ÂÛ¡£µ±²»ÖªµÀ×¢ÈëÔ­ÀíµÄʱºò»á¾õµÃºÜÉñÆ棬Ôõô¾Í±»×¢ÈëÁËÄØ£¿ ......

SQLÓï¾äЧÂÊ

 1. SQLÓÅ»¯µÄÔ­ÔòÊÇ£º½«Ò»´Î²Ù×÷ÐèÒª¶ÁÈ¡µÄBLOCKÊý¼õµ½×îµÍ,¼´ÔÚ×î¶ÌµÄʱ¼ä´ïµ½×î´óµÄÊý¾ÝÍÌÍÂÁ¿¡£
µ÷Õû²»Á¼SQLͨ³£¿ÉÒÔ´ÓÒÔϼ¸µãÇÐÈ룺
¼ì²é²»Á¼µÄSQL£¬¿¼ÂÇÆäд·¨ÊÇ·ñ»¹ÓпÉÓÅ»¯ÄÚÈÝ
¼ì²é×Ó²éѯ ¿¼ÂÇSQL×Ó²éѯÊÇ·ñ¿ÉÒÔÓüòµ¥Á¬½ÓµÄ·½Ê½½øÐÐÖØÐÂÊéд
¼ì²éÓÅ»¯ ......

sqlÄ£ºý²éѯ

SELECT * from user WHERE name LIKE '%Èý%';
½«»á°ÑnameΪ“ÕÅÈý”£¬“Èý½Å蔣¬“ÌÆÈý²Ø”µÈµÈÓГÈý”µÄÈ«ÕÒ³öÀ´£»
ÔÚ½øÐÐÊý¾Ý¿â²éѯʱ£¬ÓÐÍêÕû²éѯºÍÄ£ºý²éѯ֮·Ö¡£
Ò»°ãÄ£ºýÓï¾äÈçÏ£º
SELECT ×ֶΠfrom ±í WHERE ij×ֶΠLike Ìõ¼þ
ÆäÖйØÓÚÌõ¼þ£¬SQLÌṩÁËËÄÖÖÆ¥ÅäÄ£Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ