SQL中使用WITH 語句的查詢
sql with as 用法(適用sqlserver,好像oracle也適用) Server 2005中提供了公用表表達式(CTE),使用CTE,可以使SQL語句的可維護性,同時,CTE要比表變量的效率高得多。
下面是CTE的語法: [ WITH
如下面的SQL語句將無法正常使用CTE: with cr as ( select CountryRegionCode from *yRegion where Name like 'C%' ) select * from *yRegion -- 應將這條SQL語句去掉 -- 使用CTE的SQL語句應緊跟在相關的CTE后面 -- select * from *rovince 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 * = * and * = * 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 *yRegion where Name like @s ) select * from *rovince where CountryRegionCode in (select * from t_tree) 7、CTE除了可以簡化嵌套SQL語句外,還可以進行遞歸調用。
VBA中的WITH 語句用法 及含義
通俗點講with的作用就是簡化代碼,讓代碼簡潔易懂
讓你不需要輸入重復的內容
例如:
With [A1]
.RowHeight = 10
.ColumnWidth = 15
End With
相當于
[A1].RowHeight = 10
[A1].ColumnWidth = 15
省去了輸入很多[A1]
也就是說with中以 . 開頭的就相當于
WITH后的對象 .什么什么什么
android 中的sqlite語句怎么使用占位符
withValue1:(NSString*) value1
withValue2:(NSString*) value2
withValue3:(NSString*) value3
{
NSString * sql = [NSStringstringWithFormat:@"insert into members('name','email','birthday') values (?,?,?)"];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, [sqlUTF8String], -1, &statement,nil) ==SQLITE_OK){
sqlite3_bind_text(statement,1, [value1 UTF8String], -1,NULL);
sqlite3_bind_text(statement,2, [value2 UTF8String], -1,NULL);
sqlite3_bind_text(statement,3, [value3 UTF8String], -1,NULL);
}
if (sqlite3_step(statement) !=SQLITE_DONE) {
android sqlite 求sql語句查詢當天、本周、本月的數據~網上方法大部分
$ sqlite3SQLite version 3.7.7 2011-06-23 19:49:22Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite>
sqlite> select datetime("now");2014-01-06 03:50:08sqlite> select datetime("now", "start of day");2014-01-06 00:00:00sqlite> select date('now','weekday 1');2014-01-06
sqlite> select datetime("now", "start of month");2014-01-01 00:00:00
sqlite 使用sql語句的問題
路過,順便試了下,可以的啊!
root@DPtech /proc$ sqlite3
SQLite version 3.6.11
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table tb(id integer, value text);
sqlite> insert into tb(id) values(1);
sqlite> insert into tb values(2, '22');
sqlite> select * from tb;
1|
2|22
sqlite> select * from tb where value isnull;
1|
sqlite>
轉載請注明出處華閱文章網 » sqlitewith語句