Ⅰ 如何查詢資料庫中有相同欄位的數據
查看可用如下方法:
1、創建測試表,插入數據:
1
2
3
4
5
6
7
8
9
10
11
12
13
create table proct
(id int,
name varchar(10),
totol int)
insert into proct values (1,'香蕉',100)
insert into proct values (2,'橘子',67)
insert into proct values (3,'葡萄',89)
insert into proct values (4,'蘋果',235)
insert into proct values (5,'香蕉',77)
insert into proct values (6,'芒果',34)
insert into proct values (7,'葡萄',78)
insert into proct values (8,'梨',24)
表中數據如:
2、如果查詢name列有重復的數據,可執行sql語句:
1
select * from proct where name in (select name from proct group by name having COUNT(*)>1)
說明:查詢的結果就是香蕉和葡萄在表中是有重復的,要把香蕉和葡萄的所有記錄都查詢出來,結果如圖:
Ⅱ sql怎麼查某個欄位相同的數據
select
column_name,data_type
from
information_schema.columns
where
table_name
=
'table_1'
and
column_name='a'
如果把 and
column_name='a'
去掉,則會顯示表的所有欄位的數據類型