select ( case when gender=1 then ‘男’ else ‘女’ end)as gender from rzs_person
說明:字段轉換。
sql=“select distinct 籍貫 from 表名”
說明:去除相同部分。
SQL: insert into A(a,b,c)
select top 3 a,b,c from B
說明:A,B是表,而且字段對應。
select * from t_dingfang where now_time between ‘"&time;_fir& “’ and ‘” &time;_end& “‘order by id
SQL: select * into b from a where 1<>1
說明:複製表(只複製結構,源表名:a 新表名:b)
SQL: insert into b(a, b, c) select d,e,f from b;
說明:拷貝表(拷貝數據,源表名:a 目標表名:b)
SQL: select a,b,c from a union select d,e,f from b;
說明:合併數據(表名1:a 表名2:b)
SQL: select a,b,c from a where a IN (select d from b )
或者
SQL: select a,b,c from a where a IN (1,2,3)
說明:子查詢(表名1:a 表名2:b)
SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
說明:顯示文章、提交人和最後回復時間
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
SQL: select * from (SELECT a,b,c FROM a) T where t.a > 1;
說明:外連接查詢(表名1:a 表名2:b)
SQL:SELECT NEWID()
說明:在線視圖查詢(表名1:a )