SQLÖÐEXISTSµÄÓ÷¨
±ÈÈçÔÚNorthwindÊý¾Ý¿âÖÐ
ÓÐÒ»¸ö²éѯΪ
SELECT c.CustomerId, CompanyName
from Customers c
WHERE EXISTS(
SELECT OrderID from Orders o
WHERE o.CustomerID = cu.CustomerID)
ÕâÀïÃæµÄEXISTSÊÇÈçºÎÔË×÷ÄØ£¿×Ó²éѯ·µ»ØµÄÊÇOrderId×ֶΣ¬¿ÉÊÇÍâÃæµÄ²éѯҪÕÒµÄÊÇCustomerIDºÍCompanyName×ֶΣ¬ÕâÁ½¸ö×ֶο϶¨²»ÔÚOrderIDÀïÃæ°¡£¬ÕâÊÇÈçºÎÆ¥ÅäµÄÄØ£¿
EXISTSÓÃÓÚ¼ì²é×Ó²éѯÊÇ·ñÖÁÉٻ᷵»ØÒ»ÐÐÊý¾Ý£¬¸Ã×Ó²éѯʵ¼ÊÉϲ¢²»·µ»ØÈκÎÊý¾Ý£¬¶øÊÇ·µ»ØÖµTrue»òFalse
EXISTS
Ö¸¶¨Ò»¸ö×Ó²éѯ£¬¼ì²âÐеĴæÔÚ¡£
Óï·¨
EXISTS subquery
²ÎÊý
subquery
ÊÇÒ»¸öÊÜÏÞµÄ SELECT Óï¾ä (²»ÔÊÐíÓÐ COMPUTE ×Ó¾äºÍ INTO ¹Ø¼ü×Ö)¡£Óйظü¶àÐÅÏ¢£¬Çë²Î¼û SELECT ÖÐÓйØ×Ó²éѯµÄÌÖÂÛ¡£
½á¹ûÀàÐÍ
Boolean
½á¹ûÖµ
Èç¹û×Ó²éѯ°üº¬ÐУ¬Ôò·µ»Ø TRUE¡£
ʾÀý
A. ÔÚ×Ó²éѯÖÐʹÓà NULL ÈÔÈ»·µ»Ø½á¹û¼¯
Õâ¸öÀý×ÓÔÚ×Ó²éѯÖÐÖ¸¶¨ NULL£¬²¢·µ»Ø½á¹û¼¯£¬Í¨¹ýʹÓà EXISTS ÈÔȡֵΪ TRUE¡£
USE Northwind
GO
SELECT CategoryName
from Categories
WHERE EXISTS (SELECT NULL)
ORDER BY CategoryName ASC
GO
B. ±È½ÏʹÓà EXISTS ºÍ IN µÄ²éѯ
Õâ¸öÀý×ӱȽÏÁËÁ½¸öÓïÒåÀàËƵIJéѯ¡£µÚÒ»¸ö²éѯʹÓà EXISTS ¶øµÚ¶þ¸ö²éѯʹÓà IN¡£×¢ÒâÁ½¸ö²éѯ·µ»ØÏàͬµÄÐÅÏ¢¡£
USE pubs
GO
SELECT DISTINCT pub_name
from publishers
WHERE EXISTS
(SELECT *
from titles
WHERE pub_id = publishers.pub_id
AND type = \'business\')
GO
-- Or, using the IN clause:
USE pubs
GO
SELECT distinct pub_name
from publishers
WHERE pub_id IN
(SELECT pub_id
from titles
WHERE type = \'business\')
GO
ÏÂÃæÊÇÈÎÒ»²éѯµÄ½á¹û¼¯£º
pub_name
----------------------------------------
Algodata Infosystems
New Moon Books &n
Ïà¹ØÎĵµ£º
Ëæ×ÅB/SģʽӦÓÿª·¢µÄ·¢Õ¹£¬Ê¹ÓÃÕâÖÖģʽ±àдӦÓóÌÐòµÄ³ÌÐòÔ±Ò²Ô½À´Ô½¶à¡£µ«ÊÇÓÉÓÚ³ÌÐòÔ±µÄˮƽ¼°¾ÑéÒ²²Î²î²»Æ룬Ï൱´óÒ»²¿·Ö³ÌÐòÔ±ÔÚ±àд´úÂëµÄʱºò£¬Ã»ÓжÔÓû§ÊäÈëÊý¾ÝµÄºÏ·¨ÐÔ½øÐÐÅжϣ¬Ê¹Ó¦ÓóÌÐò´æÔÚ°²È«Òþ»¼¡£Óû§¿ÉÒÔÌá½»Ò»¶ÎÊý¾Ý¿â²éѯ´úÂ룬¸ù
¾Ý³ÌÐò·µ»ØµÄ½á¹û£¬»ñµÃijЩËûÏëµÃÖªµÄÊý¾Ý£¬Õâ¾ÍÊÇËùνµÄSQL ......
"SQL Server °²×°³ÌÐòÎÞ·¨»ñÈ¡ ASPNET ÕÊ»§µÄϵͳÕÊ»§ÐÅÏ¢"
½â¾ö°ì·¨£º
ÓÃaspnet_regiisʵÓù¤¾ßжÔغÍÖØа²×°Ò»Ï¾ͿÉÒÔÁË¡£
¾ßÌåµÄ²Ù×÷£º
1¡¢½øÈëCMD£º
C:\windows\microsoft.net\framework\v2.0.50727Îļþ¼ÐÏ£¬ÔËÐÐaspnet_regiis -uжÔØ
È»ºóÔËÐÐaspnet_regiis -i ÖØа²×°£¬ÉÏÊöÎÊÌâ¼´¿É½â¾ö¡£
2¡¢C:\WINDOWS\ ......
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
Go
----½ØÈ¡×Ö·û´®£¬²¢³öÈ¥html
create FUNCTION [dbo].[CutString] (@str varchar(1000),@length int)
RETURNS varchar(1000) AS
BEGIN
declare @mainstr varchar(1000)
declare @substr varchar(1000)
if(@str is not null or @st ......
×÷Õß
£º
Takayuki Hoshino
׫¸åÈË
£º
Juergen Thomas
¼¼
Êõ
ÉóÔÄÈË
£º
Sanjay Mishra
SQL Server Ϊ SAP Ó¦ÓóÌÐòÌṩÁË׿ԽµÄÊý¾Ý¿âƽ̨¡£ÏÂÁн¨Òé¸ÅÊöÁËÕë¶Ô SAP ʵÏÖά»¤ SQL Server Êý¾Ý¿âµÄ×î¼Ñ×ö·¨¡£
ÿÌìÖ´ÐÐÍêÕûÊý¾Ý¿â±¸·Ý
´Ó
¼¼Êõ½Ç¶ÈÀ´Ëµ£¬Áª»ú±¸·Ý SAP Êý¾Ý¿â²»³ÉÎÊÌâ¡£ÕâÒâζ×Å£¬×îÖ ......
ÕªÒª£º±¾ÎĽéÉÜÁËÔÚ¿Í»§»úÉÏ´¦Àí Microsoft sql server(WINDOWSƽ̨ÉÏÇ¿´óµÄÊý¾Ý¿âƽ̨) ²éѯµÄ·½Ê½£¬¸÷ÖÖ¿Í»§»úÓë sql server(WINDOWSƽ̨ÉÏÇ¿´óµÄÊý¾Ý¿âƽ̨) µÄ½»»¥·½Ê½£¬ÒÔ¼° sql server(WINDOWSƽ̨ÉÏÇ¿´óµÄÊý¾Ý¿âƽ̨) ÔÚ´¦Àí¿Í»§»ú³ÌÐòµÄÇëÇóʱÐèÒªÍê³ÉµÄ¹¤×÷¡£
¼ò½é
¡¡¡¡Microsoft(R) sql server(WINDOWSƽ̨ÉÏÇ¿ ......