1 / 17

PHP 與 MySQL 入門學習指南

PHP 與 MySQL 入門學習指南. 第 26 章 運算式與相關函式. 凱文瑞克 著. 算術運算 ( 一 ). 算術運算 ( 二 ). 比較運算子. 範例. 首先建立一個資料表,名稱為 customers ,內容如下所示: create table customers (customer_name varchar(10),id int,address varchar(10),phone_no varchar(10)); insert into customers values(' 郭俊及 ',1,' 高雄市 ',23423455);

Download Presentation

PHP 與 MySQL 入門學習指南

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP與MySQL入門學習指南 第 26 章 運算式與相關函式 凱文瑞克 著

  2. 算術運算(一)

  3. 算術運算(二)

  4. 比較運算子

  5. 範例 • 首先建立一個資料表,名稱為 customers,內容如下所示: • create table customers (customer_name varchar(10),id int,address varchar(10),phone_no varchar(10)); • insert into customers values('郭俊及',1,'高雄市',23423455); • insert into customers values ('莊啟明',4,'台北市',46645625); • insert into customers values ('周立華',3,'台北縣',24552355); • insert into customers values ('陳例夫',2,'高雄市',36234523); • insert into customers values ('鍾馗文',5,'台北縣',23534511); • insert into customers values ('鄭誠新',6,'台北市',65757567); • insert into customers values ('吳文華',8,'台北縣',97858676); • insert into customers values ('王一銘',7,'台北市',89563677); • insert into customers values ('趙紫新',9,'高雄市',95795643);

  6. 以比較運算子查詢(一)

  7. 以比較運算子查詢(二)

  8. 邏輯運算(一) • AND 運算子 (&&) • 當我們想要取出工作時段為日班,且工作年資在五年以下的員工資料時,我們便可以使用下列的敘述: • SELECT * FROM SALARY WHERE WORKTIME='DAY' AND EXP<=5;

  9. 邏輯運算(二) • 有一家餐廳每年都會發給年終獎金,每個員工可以領多少年終獎金,是以他的基本月薪和工作年資來決定。今年老闆決定發出的獎金是每人基本月薪的三倍,同時每一年的年資再加發1000元,現在如果我們要看看日班中是否有人可以領到10萬元,他的查詢於法如下: SELECT * FROM SALARY WHERE WORKTIME='DAY' AND ((BASE_SALARY*3)+(EXP*2)) >=100000;

  10. 邏輯運算(三) • OR 運算子 (||) • 當我們想要取出工作時段為日班,或工作年資在五年以下的員工資料時,我們便可以使用下列的敘述: SELECT * FROM SALARY WHERE WORKTIME='DAY' AND EXP<=5;

  11. 邏輯運算(四) • NOT 運算子 (!) SELECT * FROM SALARY WHERE NOT WORKTIME='NIGHT'; SELECT * FROM SALARY WHERE JOB IS NOT NULL;

  12. 邏輯運算(五) • LIKE 運算子 • 利用 = 運算子,我們可以取出某一段與特定字串完全相同的資料,但是有的時候我們並不需要和這特定字串完全相同,只要它的其中某一部分和這個特定字串相便可以,碰到這種情況,就可以使用 LIKE 運算, LIKE 可以和萬用字元組合在一起使用。

  13. 邏輯運算(六) • % 萬用字元 欄位名稱 LIKE %<值>  或  欄位名稱 LIKE * <值>

  14. 邏輯運算(七) • _或 ? 萬用字元 • % 是以一種可以替代任何字元的萬用字元,但是除此之外還有一種萬用字元'_' 或 '?',可以用來替代一個字元,它的用法如下: 欄位名稱 LIKE _<值> 或 欄位名稱 LIKE ?<值>

  15. 字串函式(一)

  16. 字串函式(二)

  17. 字串函式(三)

More Related