簡單的查詢

2021-10-10 08:44:37 字數 2067 閱讀 2395

– 查詢語法

– 簡單查詢 select 欄位名1,欄位名2,欄位名3 from 表名 — 查詢這張表中含有這些欄位的所有資訊

select stuid,stuname,gender,age from studentinfo;

– select * from 表名 ,號代表所有字段 ,我們不推薦使用 我要什麼資訊就查詢什麼字段

select * from studentinfo

– 查詢某一條資訊,我們要用where 進行過濾

select * from studentinfo where stuid = 『10』;

select * from studentinfo where stuname = 『王志強』;

– 查詢的時候可以給字段起別名 語法 as 別名

select stuid as 學號,stuname as 姓名,gender as 性別,age as 年齡 from studentinfo;

– 條件查詢

– 查詢年齡在23歲以上的學生 姓名,年齡,性別,出生如期

select stuname,age,gender,birthday from studentinfo where age>23;

select

stuname,age,gender,birthday

from

studentinfo

where

age>23;

– 查詢學生表中有一位同學的年齡為null,並且性別為男

select

stuname,age,gender,birthday

from

studentinfo

where

age is null

andgender =『男』;

– 查詢學生表中有一位同學的年齡為null,或者性別為男

select

stuname,age,gender,birthday

from

studentinfo

where

age is null

orgender =『男』;

– 在studentinfo表中查詢出年齡大於20歲的女生資訊

select * from studentinfo where age >『20』 and gender =『女』;

– 在studentinfo表中查詢出家不在鄭州的年齡或者年齡不到21歲的學生資訊

select stuname,age,gender,birthday,city from studentinfo where city <> 『鄭州』 or age <21;

– 在studentinfo表中查詢出不是1班的學生資訊

select stuname,age,gender,birthday,city,classid from studentinfo where classid <> 1012;

select stuname,age,gender,birthday,city,classid from studentinfo where not (classid=『1012』);

– 消除重複行distinct 去重 那個欄位的值重複了就在那個字段前面加上distinct 關鍵字,

select distinct stuname from studentinfo ;

– limit用法,我們分頁sql ,limit偏移量,它有兩個引數 limit 2 5

– limit 2 顯示前2條資料

– limit 2 5 從第2條開始顯示5條,不包括第2條資料

select stuid, stuname,age,gender,birthday,city,classid from studentinfo limit 2;

select stuid, stuname,age,gender,birthday,city,classid from studentinfo limit 2,5;

– 單排序 用的關鍵字order by desc降序 從大到小 asc公升序從小到大

select age,stuname,gender,birthday,city from studentinfo order by age desc;

簡單的查詢

查詢全部的行和列。select from 表名 查詢部分的行和列。select 列名 1,列名 2,from 表名 where 條件。在查詢中使用列名的別名。使用as 字句來改變結果中列的名種。select user as 使用者名稱 from 表名 使用 來改變結果中列的名種。select use...

Oracle的簡單查詢

條件判斷子句 區間,使用比較運算子 between and oracle的簡單查詢 delete from emp where sal between 2500 and 3000 oracle的簡單查詢 delete from emp where deptno 30 查詢emp表中名字中第乙個字元為...

簡單的mysql查詢

mysql是基於客戶機 伺服器的資料庫。客戶機 伺服器應用分為兩個不同的部分。伺服器部分是負責所有資料訪問和處理的乙個軟體。要連線mysql需要知道如下 主機名 本地為localhost 埠 預設為3306,如更改必須加上此項 使用者名稱密碼 show databases use databasen...