»ñÈ¡ÅŶÓ˳Ðò T£­SQL½Ì°¸_SQL SERVERÊý¾Ý¿â_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

»ñÈ¡ÅŶÓ˳Ðò T£­SQL½Ì°¸

×÷ÕߣººÚ¿Í·ÀÏßÍø°²SQLά»¤»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²SQLά»¤»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£ºË³ÐòÅŶӻñÈ¡50.0000
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£ºÒýÑÔ£¬»ù´¡£º TOP ×Ö¾äÔÊÐíÖ¸¶¨ WITH TIES¡££¨¶àÐÐͬ룩 SELECT TOP 5 WITH TIES title_id,price,title_name FROM title ORDER BY price DESC ½á¹û£º title_id price title_name -------- ...

ÒýÑÔ£¬»ù´¡£º

TOP ×Ö¾äÔÊÐíÖ¸¶¨ WITH TIES¡££¨¶àÐÐͬ룩

SELECT TOP 5 WITH TIES title_id,price,title_name
FROM title
ORDER BY price DESC

½á¹û£º

title_id price title_name
-------- --------------------- ------------------------------
Tt005 80.0000 Title_Name_5
Tt013 70.0000 Title_Name_13
Tt012 65.0000 Title_Name_12
Tt010 55.0000 Title_Name_10
Tt002 50.0000 Title_Name_2
Tt004 50.0000 Title_Name_4
Tt008 50.0000 Title_Name_8
Tt014 50.0000 Title_Name_14

(8 row(s) affected)


·½·¨Ò»£º±ê×¼µÄ SQL ·½·¨£ºÀûÓÃÊÓͼ
¶ÔÓÚ´ó±íÀ´Ëµ£¬ÐÔÄܽ«ÏÔÖø½µµÍ£¬ÒòΪ¶ÔÿһÐж¼ÒªÉ¨ÃèÒ»´Î¸Ã±í¡£

CREATE VIEW ranked_sales(rank,title_id,price,title_name)
AS
SELECT
(SELECT COUNT(DISTINCT T2.price) FROM title AS T2
WHERE T2.price>=T1.price) AS rank,
title_id,
price,
title_name
FROM title AS T1 WHERE price IS NOT NULL
GO

SELECT * FROM ranked_sales WHERE rank<=10 ORDER BY rank
GO

½á¹û£º
rank title_id price title_name
----------- -------- --------------------- ------------------------------
1 Tt005 80.0000 Title_Name_5
2 Tt013 70.0000 Title_Name_13
3 Tt012 65.0000 Title_Name_12
4 Tt010 55.0000 Title_Name_10
5 Tt002 50.0000 Title_Name_2
5 Tt004 50.0000 Title_Name_4
5 Tt008 50.0000 Title_Name_8
5 Tt014 50.0000 Title_Name_14
6 Tt001 40.0000 Title_Name_1
7 Tt006 39.0000 Title_Name_6
8 Tt007 38.0000 Title_Name_7
9 Tt009 35.0000 Title_Name_9
10 Tt011 33.0000 Title_Name_11

    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-10454-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-03-21 03:04:41  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer