Ä¿µÄ£ºµ±col1 Ϊ A ʱ µÃ³öCOL2ÏàÓ¦µÄÖµ11,µ±col1 Ϊ B ʱ µÃ³öCOL2ÏàÓ¦µÄÖµ33,µ±col2Ϊ D ʱ µÃ³öcol2µÄֵΪ 22£¬±íÖÐÎÞ D Ïà¹ØµÄÊý¾Ý£¬Òò´ËȡͨÓõÄ*µÄÖµ22select col1,col2 from table_name where col1='D' or (col1='*' and not exists( select 1 from table_name b where b.col1='D' )); àÅ ³ýÁËǶÌ×û±ðµÄ·½·¨Â𣿠¼ÙÈç col1 col11 ... ºÃ¶àÁж¼ÊôÓÚÕâÖÖÇé¿ö£¬¾ÍÊÇÈç¹û´æÔÚÔòÑ¡Ôñ´æÔڵģ¬Èç¹û²»´æÔÚ¾ÍÑ¡Ôñ * µÄ¡£ÄÇÆñ²»ÊÇҪǶÌ׺ܶàSQL£¿ select col1,col2 from table_name where col1 in('D','E','F'.....) or (col1='*' and not exists( select 1 from table_name b where b.col1 in ('D','E','F'.....) ));
ÏÖÓÐÒÔÏÂÊý¾Ý£º ID Name 1 Jack,Tom,Ben 2 Mary,Simth,Tony,Jay ת»»Îª£º ID Name 1 Jack 1 Tom 1 Ben 2 Mary 2 Simth 2 Tony 2 Jay ÒªÇóʹÓÃSQL²éѯÍê³É£¬ÓÉÓÚÌõ¼þÏÞÖÆ£¬²»ÄÜʹÓà ......