簡單型別的資料查詢

2021-07-09 09:05:19 字數 2006 閱讀 9284

查詢的基本結構

—投影操作

.概念:投影操作是查詢語句裡必須有的子句,關鍵字則為select。它將選擇對錶中那些列進行操作,這些列將出現在結果裡

.關聯式資料庫中的投影操作是指從關係中選擇出若干屬性列組成新的關係      select 列1,列2 from 表名;

.表字首

-select t_student.姓名 from 表名;

.列的別名

.計算列

-在資料管理系統中,我們也可以執行返回計算列的select查詢

.排除重複資料

-資料庫表的同列中,經常有相同值多次出現。又是,我們需要確保返回唯一的資料行。

這時我們需要使用distinct關鍵字來排除重複資料。

.返回限定的函式

-在mysql中可以限制查詢的行數,並制定從第幾行開始到第幾行結束

-注意:limit序號是從0開始。limut只能用於mysql中

選擇操作

-select 姓名,年齡 from t_student 

-執行範圍測試

.乙個範圍搜尋,大於等於下限

-定義集合關係

.在指定的某幾個值中進行搜尋

.標準結構   select 列a,列b from 表名 where 列c in(值集合)

-模糊查詢

.模糊查詢是一種比較實用的過濾方式,利用萬用字元來實現模糊查詢

.標準結構    select 列a,列bfrom 表名where 列c like 

第五章**演示

select * t_name,t_*** from yuangong;       //多行查詢

cerate table gongsi1 select * from gongsi;

select gongsi1.t_name from gongsi1;

select concat (t_name,'-',t-address) as 『公司名稱和位址』 from gongsi;     

//想要全部顯示在select後面加*,前面想要顯示什麼就加g.名稱,記住後面要跟as g

select t_age+10 from yuangong;          //操作臨時表

select t_name from gongis

排除重複

select distinct t_name from gongsi           //distinct排除重複,只能對乙個要求去重複

控制返回行

select * from gongsi where t_id>=2 and t_id<=3;

select * from gongsi limit 2,2;             //第乙個引數是從0開始的   第乙個引數表示從第幾行開始返回,第二個引數表示返回幾行

如果只有乙個引數,第乙個引數表示從0開始,

選擇操作

select * from gongsi where t_address="  ";      //檢視選擇類資料

select * from yuangong ;

select * from gongsi where t_address is null         //查詢公司為空的資料   不為空把is改為is not null

select * from yuangong wher t_age berween 18 and 25;        //範圍 包含

查詢集合

select * from yuangong where t_age in (18,19,20);          //範圍查詢   不在這個範圍用not in

模糊查詢

select * from yuangong where t_name like '王%';         //模糊查詢   使用萬用字元查詢  萬用字元在前在後都能查詢出來

如果兩個萬用字元就不能查詢出來   可通過兩個__來查詢兩字元的

以w開始倒數第二個是n

select * from yuangong where t_name like 'w%n_';

簡單的資料查詢

簡單的資料查詢 簡單的查詢語句 select from 投影操作 seleact 列1,列2 from 表名 列名列表幾種書寫方式 1.如果我們選擇某個表中的多個列,那麼列名之間用逗號分隔開 2.如果是單個列,只需要列出該列的列名即可 3.如果選擇所有的列,可以簡單的用 號帶代替列名列表。如何查詢 ...

簡單的資料查詢

投影操作 select 列名列表 from 表名 如果選擇某個表中的多個列,那麼烈與列之間用逗號隔開 如果是單個列,只需要列出該列即可 如果選擇所有列,可以用簡單的 號代替列名列表 理解表字首 對投影的列進行標識 列表名 就是對要投影的列命名,便於讀懂要投影的列的意思,如select count t...

mysql bit型別資料查詢

mysql bit資料直接查詢會顯示亂碼 在做hibernate開發時發現,pojo中定義乙個boolean hbm.xml中對映成 在mysql中轉換成 bit 1 型別資料 直接查詢 select from tablename or select from tablename 顯示亂碼,true...