With用法总结
with介词短语,从功能上来讲,介词短语可以做表语、宾语、定语、状语等,主要看with短语在句中的位置和相对应的功能,来判断是否合乎句子的逻辑表达。(with 短语的逻辑主语要与句意所要表达的修饰词一致,不能有歧义)
with引导的独立主格结构,在句末修饰前面的句子或动作
OG-19 with more of the amino acids essential to the human diet.
R:rice has protein of higher quality than that in
OG-78
(C) with the result of loss of vigor, or spreading
R:resulting in loss of vigor, or spread
应用with结构不存在正确性问题,只是相对resulting不简洁
with/without + S1 + doing/based on/介词短语/adj./noun + SVO做独立主格结构
OG-25
The end of the eighteenth century saw the emergence of prize-stock breeding, with individual bulls and cows receiving awards, put on show.
R:exciting
在主谓宾句子中如果想作状语或修饰主语的定语, 就要把介词短语提至谓语动词之前以避免产生歧义(不知是修饰主语还是宾语)。主语,with短语,谓语+宾语
OG-179
During the early years of European settlement on a continent that was viewed as "wilderness" by the many Pilgrims and pioneers from hardship, or even death.
R:Native Americans, with their intimate knowledge of the ecology of the land, helped to rescue
OG-205
The peaks of a mountain range, acting like rocks in a streambed, produce ripples in the air flowing over them; the resulting flow pattern, with(E)stationary crests and troughs although they are formed by rapidly moving air, is
R:crests and troughs that remain stationary although the air that forms them is moving rapidly, is
Choice E uses the correct verb form, is, but it incorrectly introduces a dependent adverbial although clause into a prepositional phrase (with crests ...).
with紧跟在中心词后作修饰宾语的定语, 表限定。
OG-141
all patients receiving
hearts or other organs must take antirejection drugs for the rest of their lives.
(B)Besides transplants involving identical twins with the same genetic endowment
(D)Aside from a transplant between identical twins with the same genetic endowment
R:Unless the transplant involves identical twins who have the same genetic endowment(nonrestrictive clause) In B and D the expression identical twins with the same genetic endowment wrongly suggests that only some identical twin pairs are genetically identical.
OG-152
When the technique known as gene-splicing was invented in the early 1970's, it was feared that scientists might inadvertently create an "Andromeda strain," a microbe never before seen on Earth that might escape from the laboratory and against it.
(E)kill vast numbers of humans with no natural defenses against them
R:kill vast numbers of humans who would have no natural defenses against it(nonrestrictive clause) OG-229
The colorization of black-and-white films by computers is defended by those who own the film rights, for the process can mean increased revenues for them; many others in the film industry, however, contend that (D)likening it to a Greek statue with lipstick put on it
R:likening it to putting lipstick on a Greek statue
主语+谓语+宾语,with短语。with短语修饰宾语,表示“有”的意思。
OG-114
From the bark of the paper birch tree the Menomini crafted a canoe about twenty feet long and two feet wide, with small ribs and rails of cedar, which could carry four persons or eight hundred pounds of R:baggage yet was so light
产生歧义(不知道是修饰主语还是宾语),一般采用分词短语或从句来修饰。
OG-212
The Baldrick Manufacturing Company has for several years followed a policy (E)with the aim to decrease operating costs and to improve(歧义)
with the aim... improve can easily be construed as referring to the Baldrick Manufacturing Company and so does not refer unequivocally to policy.
with短语作副词时不可以修饰名词
OG-192
Cajuns speak a dialect brought to southern Louisiana by the four thousand Acadians who migrated there in 1755; their language is basically seventeenth-century French and Italian words.
R:to which English, Spanish, and Italian words have been added(正确答案)
(D)with English, Spanish, and Italian words having been added to it
一般用法,with词组
crowd with(OG-170),along with(OG-201),associated with(OG-219),credit with(OG-226),face with(OG-247),comparison with(OG-254),collision with(OG-257)。
第二篇:SQL 中With as 的用法
SQL 中With as 的用法
一.WITH AS的含义
WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到。有的时候,是为了让SQL语句的可读性更高些,也有可能是在UNION ALL的不同部分,作为提供数据的部分。
特别对于UNION ALL比较有用。因为UNION ALL的每个部分可能相同,但是如果每个部分都去执行一遍的话,则成本太高,所以可以使用WITH AS短语,则只要执行一遍即可。如果WITH AS短语所定义的表名被调用两次以上,则优化器会自动将WITH AS短语所获取的数据放入一个TEMP表里,如果只是被调用一次,则不会。而提示materialize则是强制将WITH AS短语里的数据放入一个全局临时表里。很多查询通过这种方法都可以提高速度。
二.使用方法
先看下面一个嵌套的查询语句:
select * from person.StateProvince where CountryRegionCode in
(select CountryRegionCode from person.CountryRegion where Name like 'C%')
上面的查询语句使用了一个子查询。虽然这条SQL语句并不复杂,但如果嵌套的层次过多,会使SQL语句非常难以阅读和维护。因此,也可以使用表变量的方式来解决这个问题,SQL语句如下:
declare @t table(CountryRegionCode nvarchar(3))
insert into @t(CountryRegionCode) (select CountryRegionCode from person.CountryRegion where Name like 'C%')
select * from person.StateProvince where CountryRegionCode in (select * from @t)
虽然上面的SQL语句要比第一种方式更复杂,但却将子查询放在了表变量@t中,这样做将使SQL语句更容易维护,但又会带来另一个问题,就是性能的损失。由于表变量实际上使用了临时表,从而增加了额外的I/O开销,因此,表变量的方式并不太适合数据量大且频繁查询的情况。为此,在SQL Server 2005中提供了另外一种解决方案,这就是公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效率高得多。
下面是CTE的语法:
[ WITH <common_table_expression> [ ,n ] ]
<common_table_expression>::=
expression_name [ ( column_name [ ,n ] ) ]
AS
( CTE_query_definition )
现在使用CTE来解决上面的问题,SQL语句如下:
with
cr as
(
select CountryRegionCode from person.CountryRegion where Name like 'C%' )
select * from person.StateProvince where CountryRegionCode in (select * from cr)
其中cr是一个公用表表达式,该表达式在使用上与表变量类似,只是SQL Server 2005在处理公用表表达式的方式上有所不同。
在使用CTE时应注意如下几点:
1. CTE后面必须直接跟使用CTE的SQL语句(如select、insert、update等),否则,CTE将失效。如下面的SQL语句将无法正常使用CTE:
with
cr as
(
select CountryRegionCode from person.CountryRegion where Name like 'C%' )
select * from person.CountryRegion -- 应将这条SQL语句去掉
-- 使用CTE的SQL语句应紧跟在相关的CTE后面 --
select * from person.StateProvince where CountryRegionCode in (select * from cr)
2. CTE后面也可以跟其他的CTE,但只能使用一个with,多个CTE中间用逗号(,)分隔,如下面的SQL语句所示:
with
cte1 as
(
select * from table1 where name like 'abc%'
),
cte2 as
(
select * from table2 where id > 20
),
cte3 as
(
select * from table3 where price < 100
)
select a.* from cte1 a, cte2 b, cte3 c where a.id = b.id and a.id = c.id
3. 如果CTE的表达式名称与某个数据表或视图重名,则紧跟在该CTE后面的SQL语句使用的仍然是CTE,当然,后面的SQL语句使用的就是数据表或视图了,如下面的SQL语句所示:
-- table1是一个实际存在的表
with
table1 as
(
select * from persons where age < 30
)
select * from table1 -- 使用了名为table1的公共表表达式
select * from table1 -- 使用了名为table1的数据表
4. CTE 可以引用自身,也可以引用在同一 WITH 子句中预先定义的 CTE。不允许前向引用。
5. 不能在 CTE_query_definition 中使用以下子句:
(1)COMPUTE 或 COMPUTE BY
(2)ORDER BY(除非指定了 TOP 子句)
(3)INTO
(4)带有查询提示的 OPTION 子句
(5)FOR XML
(6)FOR BROWSE
6. 如果将 CTE 用在属于批处理的一部分的语句中,那么在它之前的语句必须以
分号结尾,如下面的SQL所示:
declare @s nvarchar(3)
set @s = 'C%'
; -- 必须加分号
with
t_tree as
(
select CountryRegionCode from person.CountryRegion where Name like @s )
select * from person.StateProvince where CountryRegionCode in (select * from t_tree)
CTE除了可以简化嵌套SQL语句外,还可以进行递归调用,