sqlÖÐllÊÇʲôÒâ˼
sql ÖÐµÄ ll ÌåÏÖÁÐÁбí (list of lists)£¬ÓÃÓÚÔÚ select Óï¾äÖн«¶à¸ö×ÓÅÌÎÊ»òÅÉÉú±íµÄЧ¹û×éºÏ³Éµ¥¸öЧ¹û¼¯£¬Ìá¸ß´úÂë¿É¶ÁÐÔ¡¢ÐÔÄܺÍÄ£¿é»¯¡£
LLÔÚSQLÖеļÄÒå
ÔÚSQLÖУ¬LL´ú±íÁÐÁбí (list of lists)¡£ËüÊÇÖ¸SELECTÓï¾äÖзµ»ØЧ¹û¼¯Ê±£¬Ê¹ÓÃÔ²À¨ºÅÀ¨ÆðÀ´µÄ×ÓÅÌÎÊ»òÅÉÉú±íµÄЧ¹û¡£
ÔõÑùʹÓÃLL
LLͨ³£ÓÃÓÚ½«¶à¸öÅÌÎÊЧ¹û×éºÏ³Éµ¥¸öЧ¹û¼¯¡£¿ÉÒÔͨ¹ýÒÔÏ·½·¨Ê¹ÓÃLL£º
SELECT * FROM ( SELECT column1 FROM table1 UNION SELECT column2 FROM table2 ) AS ll;
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄÅÌÎʽ«·µ»ØÀ´×Ôtable1ºÍtable2µÄcolumn1ºÍcolumn2µÄ×éºÏЧ¹û¼¯¡£
LLµÄÀûÒæ
ʹÓÃLL¿ÉÒÔ´øÀ´ÒÔÏÂÀûÒ棺
Ìá¸ß¿É¶ÁÐÔ£ºÍ¨¹ý½«ÖØ´óÅÌÎʲð·ÖΪ¶à¸ö½ÏСµÄÅÌÎÊ£¬¿ÉÒÔÌá¸ß´úÂëµÄ¿É¶ÁÐÔ¡£
Ìá¸ßÐÔÄÜ£º¹ØÓÚijЩÅÌÎÊ£¬Ê¹ÓÃLL¿ÉÒÔÓÅ»¯ÅÌÎÊÐÔÄÜ¡£
ʵÏÖÄ£¿é»¯£ºLL¿ÉÒÔ½«ÅÌÎÊÆÊÎöΪ¿ÉÖØÓõÄ×é¼þ£¬´Ó¶øʵÏÖÄ£¿é»¯¡£
ʾÀý
ÒÔÏÂʾÀý˵Ã÷ÎúÔõÑùʹÓÃLL£º
-- ÅÌËã×ÜÏúÊÛ¶î SELECT SUM(sales) AS total_sales FROM ( SELECT SUM(sales) AS sales FROM orders GROUP BY customer_id );
µÇ¼ºó¸´ÖÆ
Õâ¸öÅÌÎʽ«ÅÌËãËùÓпͻ§µÄ×ÜÏúÊ۶²¢ÒÔLLµÄÐÎʽ·µ»ØЧ¹û¡£
ÒÔÉϾÍÊÇsqlÖÐllÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡