mysql 例項(乙個表) 查詢

2021-09-21 01:14:34 字數 1040 閱讀 3754

以下的查詢語句中存在著多表,包含主外來鍵(這裡並未顯示)理解為主

#1查詢表中所有記錄的列1,列2 ,列3

select 列1 ,列2,列3 from 表;

#2查詢表的所有記錄

select distinct 列1 from 表;

#3 查詢表 的所有記錄

select count(*) from 表;

#4 查詢表中數範圍在60~80 的所有記錄

select * from 列 where >=60 and degree<=80;

或 __________(degree–等級)

select * from 列 where degree between 60 and 80 ;

#5 查詢表中資料為1,2,或3的記錄

select * from 表 where degree =1 or degree=2 or degree=3;

#6查詢表中列1中的value1 或列2中value2 的記錄

select * from 表 where 列1=』value1『 or 列2=『value2』;

#7 以列1降序的方式查詢表中的所有記錄

select * from 表 order by 列1 desc;

#8 以列1 公升序,列2降序 查詢表的所有記錄

select * from 表 order by 列1 asc ,列2 desc;

#9 查詢表中最高 的列1和列2

select 列1,列2 from 表 where degree=(select max(degree)from 表);

#10 查詢表中大於3,小於8的列

select 列 from 表 where degree>3 and degree<8;

#11查詢22班和11班全體學生的記錄

select * from 表 where class in (『22』,『11』);

#12 查詢student表中不姓「王」的同學記錄。

select * from student where sname not like 『王%』

mysql查詢乙個表的資料插入另乙個表

1.如果2張表的字段一致,並且希望插入全部資料,可以用這種方法 insert into 目標表 select from 表 例如 insert into t a select from t b 2.如果只希望匯入指定字段,可以用這種方法 insert into 目標表 欄位1,欄位2,select ...

MYSQL查詢 存在乙個表而不在另乙個表中的資料

a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒...

MYSQL查詢 存在乙個表而不在另乙個表中的資料

a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒 select distinct a.id from a where a.id not in ...