⑴ sql多表查詢多個欄位
SQL語句格式:
select 欄位1,欄位2,欄位3
from 表1,表2,表3
where 條件
例子:查詢s表中的sno欄位, c表中的cno欄位,j表中的jno欄位
select sno,pno,jno
from s,p,j
(1)sqlselect多個欄位擴展閱讀:
刪除語句:DELETE * FROM table_name
查詢語句:SELECT * FROM Persons WHERE ROWNUM <= 5
建立視圖:CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
⑵ SQL語句查詢多個表欄位
假設3個表分別為A,B,C
1、select a.書名,c.借閱日期 from b
left join c on b.讀者編號=c. 讀者編號
left join a on c.圖書編碼=a.圖書編碼
where b.姓名='高志遠'
2、select count(*) from b
left join c on b.讀者編號=c. 讀者編號
left join a on c.圖書編碼=a.圖書編碼
where b.姓名='高志遠'
group by a.書名
⑶ 關於用sql語句select多個欄位,該使用什麼接收的解決辦法
如果只是想要a欄位不重復的記錄,使用group
by子句即可
select
a
from
table
group
by
a
但如果想要取到a欄位為1,2,3的數據所對應的整條記錄,就比較困難,因為你的a欄位並非主鍵,存在重復的情況。如果想要處理的話,最好新建一張表,增加一個自增欄位的主鍵,就可以解決這個問題了。
⑷ sql多張表查詢多個不同欄位
selectt1.id1,t1.id2,t1.id3,t2.id5,t2.id6,t3.id8,t3.id9fromt1leftjoint2ont1.id1=t2.id1leftjoint3ont3.id1=t1.id1
⑸ SQL查詢多個欄位語句
String ser = request.getParameter("ser");
if(ser != null && ser.length() > 0){
ser="and serialno like '"+ser+"%' ";
}
String id = request.getParameter("id");
if(id != null && id.length() > 0){
id="and id like '"+id+"%' ";
}
String t1 = request.getParameter("t1");
if(t1 != null && t1.length() > 0){
t1="and dt > to_date('"+t1+"','yyyy-mm-dd hh24:mi:ss') ";
}
String t2 = request.getParameter("t2");
if(t2 != null && t2.length() > 0){
t2="and dt < to_date('"+t2+"','yyyy-mm-dd hh24:mi:ss') ";
}
String xw = request.getParameter("xw");
if(xw != null && xw.length() > 0){
xw="and type='"+xw+"'";
}
String sql="select * from lz.user_old where 1=1 "+ser+id+t1+t2+xw;
System.out.println(sql);
ResultSet rt=st.executeQuery(sql);
這個是類似的一段代碼,你可以參照改寫即可,通過第三方語言處理而組裝sql語句即可實現你所要的結果。
⑹ SQL 關聯查詢 怎麼同時關聯多個欄位
我們需要准備的材料分別是:電腦、sql查詢器。
1、首先,打開sql查詢器,連接上相應的資料庫表,以proct1表和proct2表為例。
⑺ SQL語句 如何查找一張表裡多個欄位符合條件的內容
兩個方法。這是按照你的題意是這么的,但是應該死查不出來東西的,因為A=a1 和A=a2怎麼會同時滿足,除非a1=a2,我覺得可能你題目看錯了,不是同時滿足,而是滿足條件1或條件2,這樣才會有記錄被查出來
1. select * from tab where ((A=a1 and B=b1)and(A=a2 and C=c1));
2.select * from tab where A=a1 and B=b1
intersect select * from tab where A=a2 and C=c1
⑻ sql select提取多個欄位,提取的順序是什麼
每條都是一起取的吧 第一行 a和b 第二行 a和b 這樣
⑼ 如何查詢sql 表中的多個欄位
select
*
from
表名
where
biaoboje 不等於
jinjiaje
or
jinjiaje
不等於
pijiaje
or
pijiaje
不等於
shoujiaje
不等於:sql
的不等號,即兩個尖括弧同時向中間開口,此處騰訊好像不能這樣回答
⑽ SQL重復記錄查詢 查詢多個欄位、多表查詢、刪除重復記錄的方法
SQL重復記錄查詢
1、查找表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷
select
*
from
people
where
peopleId
in
(select
peopleId
from
people
group
by
peopleId
having
count(peopleId)
>
1)
例二:
select
*
from
testtable
where
numeber
in
(select
number
from
people
group
by
number
having
count(number)
>
1
)
可以查出testtable表中number相同的記錄
2、刪除表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷,只留有rowid最小的記錄
delete
from
people
where
peopleId
in
(select
peopleId
from
people
group
by
peopleId
having
count(peopleId)
>
1)
and
rowid
not
in
(select
min(rowid)
from
people
group
by
peopleId
having
count(peopleId
)>1)
3、查找表中多餘的重復記錄(多個欄位)
select
*
from
vitae
a
where
(a.peopleId,a.seq)
in
(select
peopleId,seq
from
vitae
group
by
peopleId,seq
having
count(*)
>
1)
4、刪除表中多餘的重復記錄(多個欄位),只留有rowid最小的記錄
delete
from
vitae
a
where
(a.peopleId,a.seq)
in
(select
peopleId,seq
from
vitae
group
by
peopleId,seq
having
count(*)
>
1)
and
rowid
not
in
(select
min(rowid)
from
vitae
group
by
peopleId,seq
having
count(*)>1)
5、查找表中多餘的重復記錄(多個欄位),不包含rowid最小的記錄
select
*
from
vitae
a
where
(a.peopleId,a.seq)
in
(select
peopleId,seq
from
vitae
group
by
peopleId,seq
having
count(*)
>
1)
and
rowid
not
in
(select
min(rowid)
from
vitae
group
by
peopleId,seq
having
count(*)>1)
(二)
比方說
在A表中存在一個欄位「name」,
而且不同記錄之間的「name」值有可能會相同,
現在就是需要查詢出在該表中的各記錄之間,「name」值存在重復的項;
Select
Name,Count(*)
From
A
Group
By
Name
Having
Count(*)
>
1
如果還查性別也相同大則如下:
Select
Name,sex,Count(*)
From
A
Group
By
Name,sex
Having
Count(*)
>
1
(三)
方法一
declare
@max
integer,@id
integer
declare
cur_rows
cursor
local
for
select
主欄位,count(*)
from
表名
group
by
主欄位
having
count(*)
>;
1
open
cur_rows
fetch
cur_rows
into
@id,@max
while
@@fetch_status=0
begin
select
@max
=
@max
-1
set
rowcount
@max
delete
from
表名
where
主欄位
=
@id
fetch
cur_rows
into
@id,@max
end
close
cur_rows
set
rowcount
0
方法二
有兩個意義上的重復記錄,一是完全重復的記錄,也即所有欄位均重復的記錄,二是部分關鍵欄位重復的記錄,比如Name欄位重復,而其他欄位不一定重復或都重復可以忽略。
1、對於第一種重復,比較容易解決,使用
select
distinct
*
from
tableName
就可以得到無重復記錄的結果集。
如果該表需要刪除重復的記錄(重復記錄保留1條),可以按以下方法刪除
select
distinct
*
into
#Tmp
from
tableName
drop
table
tableName
select
*
into
tableName
from
#Tmp
drop
table
#Tmp
發生這種重復的原因是表設計不周產生的,增加唯一索引列即可解決。
2、這類重復問題通常要求保留重復記錄中的第一條記錄,操作方法如下
假設有重復的欄位為Name,Address,要求得到這兩個欄位唯一的結果集
select
identity(int,1,1)
as
autoID,
*
into
#Tmp
from
tableName
select
min(autoID)
as
autoID
into
#Tmp2
from
#Tmp
group
by
Name,autoID
select
*
from
#Tmp
where
autoID
in(select
autoID
from
#tmp2)
最後一個select即得到了Name,Address不重復的結果集(但多了一個autoID欄位,實際寫時可以寫在select子句中省去此列)
(四)
查詢重復
select
*
from
tablename
where
id
in
(
select
id
from
tablename
group
by
id
having
count(id)
>
1
)
以上就是小編為大家帶來的SQL重復記錄查詢
查詢多個欄位、多表查詢、刪除重復記錄的方法的全部內容了,希望對大家有所幫助,多多支持腳本之家~