SQL ÃæÊÔÌâ Ò»
ÌâÄ¿Ò»£º
ÓÐÁ½ÕÅ±í£º²¿Ãűídepartment ²¿ÃűàºÅdept_id ²¿ÃÅÃû³Ædept_name
Ô±¹¤±íemployee Ô±¹¤±àºÅemp_id Ô±¹¤ÐÕÃûemp_name ²¿ÃűàºÅdept_id ¹¤×Êemp_wage
¸ù¾ÝÏÂÁÐÌâĿд³ösql£º
1¡¢Áгö¹¤×Ê´óÓÚ5000µÄÔ±¹¤ËùÊôµÄ²¿ÃÅÃû¡¢Ô±¹¤idºÍÔ±¹¤¹¤×Ê£»
2¡¢ÁгöÔ±¹¤±íÖеIJ¿ÃÅid¶ÔÓ¦µÄÃû³ÆºÍÔ±¹¤id£¨×óÁ¬½Ó£©
3¡¢ÁгöÔ±¹¤´óÓÚµÈÓÚ2È˵IJ¿ÃűàºÅ
4¡¢Áгö¹¤×Ê×î¸ßµÄÔ±¹¤ÐÕÃû
5¡¢Çó¸÷²¿ÃŵÄƽ¾ù¹¤×Ê
6¡¢Çó¸÷²¿ÃŵÄÔ±¹¤¹¤×Ê×ܶî
7¡¢Çóÿ¸ö²¿ÃÅÖеÄ×î´ó¹¤×ÊÖµºÍ×îС¹¤×ÊÖµ£¬²¢ÇÒËüµÄ×îСֵСÓÚ5000£¬×î´óÖµ´óÓÚ10000
8¡¢¼ÙÈçÏÖÔÚÔÚ¿âÖÐÓÐÒ»¸öºÍÔ±¹¤±í½á¹¹ÏàͬµÄ¿Õ±íemployee2,ÇëÓÃÒ»ÌõsqlÓï¾ä½«employee±íÖеÄËùÒԼǼ²åÈëµ½employee2±íÖС£
answer:
1:Áгö¹¤×Ê´óÓÚ5000µÄÔ±¹¤ËùÊôµÄ²¿ÃÅÃû¡¢Ô±¹¤idºÍÔ±¹¤¹¤×Ê£»
select emp_id,emp_wage,dept_name from employee as e inner join department as d on e.dept_id=d.dept_id where e.emp_wage>5000 group by e.emp_id;
2:ÁгöÔ±¹¤±íÖеIJ¿ÃÅid¶ÔÓ¦µÄÃû³ÆºÍÔ±¹¤id£¨×óÁ¬½Ó£©
select dept_name,emp_id from department d left join employee e on e.dept_id=d.dept_id group by e.emp_id;
+------------+--------+
| dept_name | emp_id |
+------------+--------+
| ×Éѯ²¿ | NULL |
| Èí¼þ¿ª·¢²¿ | 1001 |
| Êг¡²ß»®²¿ | 1002 |
| ÏúÊÛ²¿ | 1003 |
| HR | 1004 |
| HR | 1005 |
| HR | 1006 |
| Èí¼þ¿ª·¢²¿ | 1007 |
+------------+--------+
3£ºÁгöÔ±¹¤´óÓÚµÈÓÚ2È˵IJ¿ÃűàºÅ
select dept_name from department d [inner] join employee e on d.dept_id=e.dept_id group by dept_name
having count(e.dept_id) >=2;
&nb
Ïà¹ØÎĵµ£º
Ò»).´´½¨²¿ÊðÏîÄ¿
1. ÔÚ“Îļþ”²Ëµ¥ÉÏÖ¸Ïò“Ìí¼ÓÏîÄ¿”£¬È»ºóÑ¡Ôñ“н¨ÏîÄ¿”¡£
2. ÔÚ“Ìí¼ÓÐÂÏîÄ¿”¶Ô»°¿òÖУ¬Ñ¡Ôñ“ÏîÄ¿ÀàÐÍ”´°¸ñÖеē°²×°ºÍ²¿ÊðÏîÄ¿”£¬È»ºóÑ¡Ôñ“Ä£°å”´°¸ñ ......
ÐÔÄܼà¿ØÖ®¼à¿ØSQLÓï¾ä
·ÖÎö±í
analyze table tablename compute statistics for all indexes;
analyze table tablename compute statistics for all indexed columns;
analyze table tablename compute statistics for table;
¼à¿ØÊÂÀýµÄµÈ´ý
select event,sum(decode(wait_Tim ......
1=1»òÕß'a'='a'µÈµÈºãµÈʽÊÇT-SQLÖбí´ïtrueµÄ·½·¨¡£ÒòΪÔÚT-SQLÖÐûÓÐtrueÕâÑùµÄ¹Ø¼ü
×Ö»òÖµ£¬ËùÒÔÐèÒª½èÖúÕâЩºãµÈʽÀ´±í´ïtrueµÄ¸ÅÄî¡£
Ïà¶ÔµÄ£¬Í¬Ñù¿ÉÒÔʹÓÃ1<>1»òÕß1=2µÈÀ´±í´ïfalse¡£
ÔÚÓ¦ÓóÌʽµÄ°²È«ÐÔ·½Ã棬ʹÓÃÕâЩʽ×ÓÊÇSQL×¢ÈëµÄ»ù±¾ÔÀí£¬ËùÒÔÔÚÆ´½ÓSQLÓï¾äµÄʱºòÒª¹ýÂ˸÷ÖÖ¸÷ÑùµÄÃô¸Ð×Ö
·û¡£
µ±È» ......
½¨Á¢Ò»¸ö Web Ó¦Ó㬷ÖÒ³ä¯ÀÀ¹¦Äܱز»¿ÉÉÙ¡£Õâ¸öÎÊÌâÊÇÊý¾Ý¿â´¦ÀíÖÐÊ®·Ö³£¼ûµÄÎÊÌâ¡£¾µäµÄÊý¾Ý·ÖÒ³·½·¨ÊÇ:ADO ¼Í¼¼¯·ÖÒ³·¨£¬Ò²¾ÍÊÇÀûÓÃADO×Ô´øµÄ·ÖÒ³¹¦ÄÜ£¨ÀûÓÃÓα꣩À´ÊµÏÖ·ÖÒ³¡£µ«ÕâÖÖ·ÖÒ³·½·¨½öÊÊÓÃÓÚ½ÏСÊý¾ÝÁ¿µÄÇéÐΣ¬ÒòΪÓα걾ÉíÓÐȱµã£ºÓαêÊÇ´æ·ÅÔÚÄÚ´æÖУ¬ºÜ·ÑÄÚ´æ¡£ÓαêÒ»½¨Á¢£¬¾Í½«Ïà¹ØµÄ¼Ç¼Ëøס£¬Ö±µ½È¡ÏûÓ ......