¼¸µÀ¾µäµÄsqlÌâÄ¿
£¨1£©±íÃû£º¹ºÎïÐÅÏ¢
¹ºÎïÈË ÉÌÆ·Ãû³Æ ÊýÁ¿
A ¼× 2
B ÒÒ 4
C ±û 1
A ¶¡ 2
B ±û 5
……
£¨ÆäËûÓû§ÊµÑéµÄ¼Ç¼´ó¼Ò¿É×ÔÐвåÈ룩
¸ø³öËùÓйºÈëÉÌƷΪÁ½ÖÖ»òÁ½ÖÖÒÔÉϵĹºÎïÈ˼Ǽ
´ð£ºselect * from ¹ºÎïÐÅÏ¢ where ¹ºÎïÈË in (select ¹ºÎïÈË from ¹ºÎïÐÅÏ¢ group by ¹ºÎïÈË having count(*) >= 2);
ÎҵĴ𰸣º
SELECT *
from purchase t
WHERE ( select count(*)
from purchase s
where s.name = t.name
) >= 2
OR
select *
from purchase name in
( select name from purchase
group by name
having count(name) >= 2
)
£¨2£©±íÃû£º³É¼¨±í
ÐÕÃû ¿Î³Ì ·ÖÊý
ÕÅÈý ÓïÎÄ 81
ÕÅÈý Êýѧ 75
ÀîËÄ ÓïÎÄ 56
ÀîËÄ Êýѧ 90
ÍõÎå ÓïÎÄ 81
ÍõÎå Êýѧ 100
ÍõÎå Ó¢Óï 49
……
£¨ÆäËûÓû§ÊµÑéµÄ¼Ç¼´ó¼Ò¿É×ÔÐвåÈ룩
¸ø³ö³É¼¨È«²¿ºÏ¸ñµÄѧÉúÐÅÏ¢£¨°üº¬ÐÕÃû¡¢¿Î³Ì¡¢·ÖÊý£©£¬×¢£º·ÖÊýÔÚ60ÒÔÉÏÆÀΪºÏ¸ñ
´ð£ºselect * f
Ïà¹ØÎĵµ£º
sql server 2005Ö»±¸·ÝÊý¾Ý¿âµÄ½á¹¹
1¡¢´ò¿ªsql server enterpirise management studio£¬ÓÃsaÕÊ»§Á¬½Óµ½Êý¾Ý¿â·þÎñÆ÷¡£
2¡¢Ñ¡ÔñÐèÒª±¸·ÝµÄÊý¾Ý¿â£¬ÓÒ»÷Êó±êÔÚµ¯³öµÄ²Ëµ¥ÖÐÑ¡Ôñ“ÈÎÎñ”——“Éú³É½Å±¾”£¬°´Õսű¾Ïòµ¼£¬ÏÂÒ»²½¾Í¿ÉÒÔÁË¡£
ÕâÑù»á½«´ËÊý¾Ý¿âÖеÄËùÓжÔÏóµÄ´´½¨³ÉÉúÒ»¸ö½Å±¾Î ......
select * from sq_donglong.achi_news where ID in (select ID from (select top 6 ID from sq_donglong.achi_news where SortID=82)a union all select ID from (select top 6 ID from sq_donglong.achi_news where SortID=84)b)
......
mysql´´½¨Êý¾Ý¿âsqlʵÀý
# MySQL-Front 3.2 (Build 2.10)
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET CHARACTER SET 'latin1' ......
1. µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä
select getdate()
2. dateadd ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
ÀýÈ磺ÏòÈÕÆÚ¼ÓÉÏ2Ìì
select dat ......