sql²éѯÓï¾äÎÊÌâ oracleµÄ - Oracle / »ù´¡ºÍ¹ÜÀí
²éѯÓÐ3ÃÅÒÔÉÏ£¨°üÀ¨3ÃÅ£©¿Î³ÌÊÇ90·ÖÒÔÉÏ£¨°üÀ¨90£©µÄѧÉúѧºÅ¼°¿Î³ÌÊý ÀýÈ磺
ѧºÅ ÐÕÃû ¿Î³ÌÃû³Æ ¿Î³Ì³É¼¨
1 ÕÅÈý ÓïÎÄ 80
2 ÀîËÄ Êýѧ 90
3 ÍõÎå Ó¢Óï 90
д³ösqlÓï¾ä¼´¿É
select ѧºÅ,count(*) from
(select ѧºÅ,¿Î³ÌÃû³Æ from table_name
where ¿Î³Ì³É¼¨>=90)
group by ѧºÅ
having count(*)>=3;
select ѧºÅ,count(¿Î³ÌÃû³Æ)
from tableѧÉú
where ¿Î³Ì³É¼¨>=90
group by ѧºÅ
having count(¿Î³ÌÃû³Æ) >= 3
Ïà¹ØÎÊ´ð£º
ÎÒÊÇÓÃÔ¶³Ì×ÀÃæÁ¬²Ù×÷·þÎñÆ÷ÉϵÄÊý¾Ý¿â¡£
ÔÚ´´½¨Ò»¸öÓû§Ö®ºó£¬ÔÙÓÃPLSQLµÇ¼£¬ÔòPLSQLËÀµôÁË¡£
ÎҹصôPLSQLÖ®ºó£¬ÓÃÆäËûÓû§Ò²²»ÄܵǼ¡£
ÎÒ°ÑoracleµÄ·þÎñÍ£Ö¹£¬½á¹û¾ÍÊÇoracleµÄ·þÎñ״̬¾ÍÍ£ÁôÔÚ¡°Í ......
¿ÉÄÜÒòΪ¹¤×÷µÄÔÒò ½Ó´¥Êý¾Ý¿âÕâ¿é±È½ÏÉÙ£¬Ö®Ç°¶¼ÊÇ×ö³ÌÐòÕâ¿é£¬Êý¾Ý¿âÕâ¿é¶¼ÓÐרÃŵÄÈËÀ´×ö ·Ö¹¤¶¼ºÜÃ÷ϸ ËùÒÔ¶ÔÊý¾Ý¿âÕâÒ»¿éÍêÈ«²»Á˽⡣ǰ¶Îʱ¼ä È¥ÃæÊÔÁ˼¸¼Ò¹«Ë¾ ¼¸ºõ¶¼ÊÇÔÚÊý¾Ý¿âÕâ¿é¹ÒµôµÄ Á¬¸ö¼òµ¥µÄSQ ......
ÏÖÔÚÓÐÁ½ÕÅ±í£ºÎÄÕÂÖ÷±íA(articleId,articleTitle)£¬ÎÄÕÂÆÀÂÛ±íB(commentId,articleId,commentTitle)
ÏÖÔÚÎÒÏëʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÁгöÎÄÕÂÁÐ±í£¬ÆäÖÐÿƪÎÄÕ±êÌâÏÂÃæÁгö´ËÎÄÕµÄÇ°2¸öÎÄÕÂÆÀÂÛ£¬ÇëÎÊsqlÓï¾äÔõôд°¡ ......
½«Ò»¸ö²éѯÓï¾ä¸³¸øÒ»¸ö±äÁ¿£¬ÈçÏ£º
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
ÔõôÑù²ÅÄÜÖ´ÐÐËüÄØ£¿
Çë¸ßÊÖ£¬ÈÊÐÖ£¬ÏÀ½ã°ï°ïæ°¡
¶àл£¬¿ÉÒÔÀ²£¬¸ßÊÖ°¡
Ö±½ÓÖ´ÐоÍÐÐÁË
exec ......
select distinct '1' t1,'2' t2,'3' t3,'4' t4 from table ²é³öÀ´µÄ½á¹ûΪ
1,2,3,4
ÎÒÏëµÃÒÔÏÂÕâÑùµÄЧ¹û
1
2
3
4
ÇëÎÊÒ»ÏÂÓÐʲô°ì·¨¿ÉÒÔ½â¾ö???
ûÓкõķ½·¨£¬ÓÃunion£¬Ò»ÌõÌõ¼Ç¼ƴ½Ó
SQL code:
wi ......