神馬雙關鍵字查詢?select * from table where 條件+條件,模糊的話可以 like 『%%_』
㈡ SQL查詢雙表,多表,綜合查詢
selectt1.編號,t1.姓名,t1.單位,t1.N列,
t2.職位,t2.N列N列2
fromt1leftoutert2
ont1.編號=t2.編號
㈢ 如何用外查詢同時實現sql語言兩個查詢功能
一、用連接查詢:
SELECT * from Student inNER JOin Score
ON Cno=2 AND Grade>=90
二、用子查詢:
SELECT * from Student where Sno in(
SELECT Sno FROM Score
WHERE Cno=2 AND Grade>90)
㈣ MYSQL中SQL雙表查詢語句怎麼寫
sql="select * from t1 right join t2 on t1.channel=t2.欄位 where t1.channel=17 limit 10"
說明:你指定了連接【right join】但是沒有指定連接條件,就會產生這樣的問題,改成上面的sql就能達到你的目的了。因為我不清楚你連接條件中【t2】表中的欄位叫什麼,所以寫了【t2.欄位】,你自己根據你的實際情況寫上去即可。
---
以上,希望對你有所幫助。
㈤ sql 兩個表 查詢
用Union沒錯!
Select aid, a1, a2 from [表a]
union all
Select bid, b1, b2 from [表b]
使用Union的關鍵點:
一、查詢結果是一個數據集,它的欄位名以第1個Select後面的欄位列表為准,後面的Select的欄位列表需要與第1個的對齊(欄位個數和數據類型相同,名稱無所謂)
例如如下這句,就是增加一條記錄。
Select aid, a1, a2 from [表a]
union all
Select bid, b1, b2 from [表b]
Union
select 0, '111', '222'
如下會出錯,因為第一個Select中的欄位 111 為整型,會造成[表b]的b1欄位內容強行向整型轉換,轉換會失敗:將 varchar 值 'b11' 轉換為數據類型為 int 的列時發生語法錯誤。
select 0, 111, '222'
Union
Select bid, b1, b2 from [表b]
二、union all中的「All」不加的話,是自動剔除重復的記錄(重復的記錄只保留1條),加上「All」則會保留所有數據。
---------------------------------
按問題補充:1)讓查詢結果添加到一張新表裡面;2)按某個條件查詢,比如查詢出結尾為22的數據。顯示a22 b22:
只需要增加幾個子句就可以了:
1)將查詢結果放到新表:
Select aid, a1, a2 into [新表名] from [表a]
union all
Select bid, b1, b2 from [表b]
--關鍵點:SELECT INTO 必須是包含 UNION 運算符的 SQL 語句中的第一個查詢。
2)增加查詢條件:
Select aid, a1, a2 from [表a] where a2 like '%22'
union all
Select bid, b1, b2 from [表b] where b2 like '%22'
--關鍵點:每個子查詢都要單獨增加相應的查詢條件!
-----------------------
對於「超時時間已到,……」:可能原因是:1、數據量過大;2、SQL的超時設置不夠長。所以你可以嘗試把SQL的超時設置長一些,比如2分鍾;再就是把這個Union拆成兩句來分別執行:
Select aid, a1, a2 into [新表名] from [表a]
Insert into [新表名] Select bid, b1, b2 from [表b]
如果還超時,那就復雜了,可能數據量太大、其他性能、索引、等綜合檢查了。
對於增加自增長欄位的問題,是這樣的,在Select into這種方式生成新表時,是無法指定自增長欄位的。所以辦法就是:先建立好表,再用Insert into的方式向裡面插入數據:
CREATE TABLE dbo.NewTABLE
(
Myid int NOT NULL IDENTITY (1, 1),
oid int NULL,
A varchar(50) NULL,
B varchar(50) NULL
) ON [PRIMARY]
GO
Insert into [NewTABLE](oid,A,B) Select aid, a1, a2 from [表a]
Insert into [NewTABLE](oid,A,B) Select bid, b1, b2 from [表b]
Go
----------------------------------
「單純的查詢時候定義自增列」,這個據我所知是不行的,不知SQL 2005是否有此功能。因為查詢的結果總是來源於現有數據或常數,且SQL的記錄是沒有行號概念的。
看能否從現有數據中的某一列通過某種計算得到一個貌似自增的結果。類似:
select *, 一個公式(某列) as MyID from [tablename]
㈥ sql like 雙重查詢
『%(select keywords from dede_arctype where id=8)%』在SQL裡面這是一個字元串,不是查詢的結果你的語句應該是:
select * from dede_archives where title like '%'+(select keywords from dede_arctype where id=8)+'%』
這樣你是能查到結果的,但是如同一樓說的,數據量大的話你機子受不了,建議換思路
㈦ sql雙條件查詢語句
select * from [table] where a = 變數 and b is not null
㈧ SQL 怎樣連接兩個查詢結果
只算平均分嗎?不考慮是否大於80吧。
select Student.*,t1.CNum,t1.Grade,(select Avg(Grade)
from SC t2
where t2.SNum=t1.SNum and Avg(Grade)>=80) as 平均分
from Student,SC t1
where
t1.SNum=Student.SNum
你說的是平均分不大於80的學生就不列出來嗎?
還是平均分低於80的學生就不顯示平均分了?
我估計你說的是前者
select Student.*,t1.CNum,t1.Grade,(select Avg(Grade)
from SC t2
where t2.SNum=t1.SNum group by t2.SNum having Avg(Grade)>=80) as 平均分
from Student,SC t1
where
t1.SNum=Student.SNum
這個顯示的是所有學生的所有成績,如果平均分大於80,就顯示平均分,小於就不顯示平均分。
如果你只要平均分大於80的學生的信息的話:
select Student.*,t1.CNum,t1.Grade,(select Avg(Grade)
from SC t2
where t2.SNum=t1.SNum) as 平均分
from Student,SC t1
where t1.SNum=Student.SNum
and (select Avg(Grade) from SC t2
where t2.SNum=t1.SNum
and group by t2.SNum)>=80
不知道你是否會要大於80分的學習的姓名啊,就是不要每科的分數,只要姓名。
㈨ sql 雙重條件查詢 會SQL的來幫個忙
你說的意思我大概明白的,你的意思是說比如我要查詢A1=6的記錄下面的一條記錄,返回的就是 兩條: 2 18 和 10 21
是這個意思吧。
這樣的話,我建立一個表測試用的:
create table test22
(
A int,
A1 varchar(20)
)
這個A1我是用字元的,有利於觀察
然後插入測試數據:
insert all
into test22 values(1,'張三')
into test22 values(2,'李四')
into test22 values(3,'張三')
into test22 values(4,'王五')
into test22 values(5,'趙六')
into test22 values(6,'前期')
into test22 values(7,'張三')
into test22 values(8,'呵呵')
into test22 values(9,'張三')
into test22 values(10,'暈')
into test22 values(11,'結束了')
into test22 values(12,'張三')
into test22 values(13,'張三')
select * from al
然後就查詢你要的:
比如我現在要查詢「欄位A1等於張三的記錄的下面的一條記錄」:
select a,a1 from test22 t1 where exists(select * from test22 t2 where t2.a=t1.a-1 and t2.a1='張三')
返回的是:
A A1
2 李四
4 王五
8 呵呵
10 暈
13 張三
OK了吧。不明白再和我說。
㈩ SQL雙表查詢,簡單語句
select b.id,b.學號,b.姓名,a.行政班名稱 from 行政班表 a,學生表 b where a.行政班編號=b.行政班