Mysql笔记
2022/1/25 19:07:17
本文主要是介绍Mysql笔记,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/* USE sql_store; #使用 name数据库 SELECT * # (明确获得的列) (*)所有列 customer_id, first_name (选这两列) FROM customers # (明确查询的表) 从 custermers 表中选择 WHERE customer_id = 1 #(按何种结果筛选) 只会得到 cusromer_id = 1 的数据 ORDER BY first_name # (根据 xx 排序 明确列) */ /* SELECT last_name, first_name, points, (points + 10) * 100 AS "discount factor" #讲运算得到的列取别名(AS)用' '或者" " 这样就可以看作字符串,可以中间加空格 FROM customers */ /* SELECT DISTINCT state #数据中本应该有两条数据含有"VA",使用关键字(DISTINCT)可以去重 FROM customers */ /* 题目: Return all the products show ther column name unit price new price (unit price * 1.1) USE sql_store; SELECT name, unit_price, (unit_price * 1.1) AS "new price" FROM products; */ /* SELECT * FROM customers WHERE birth_date >= "1990-01-01" AND points > 1000# AND OR NOT ORDER BY birth_date */ /* From the order_items table, get the items for order#6 where the total price is greater than 30 */ /* SELECT * FROM order_items WHERE order_id = 6 AND quantity * unit_price > 30 */ /* SELECT * FROM Customers WHERE state = "VA" OR state = "FL" OR state = "GA" # WHERE state IN ("VA", "FL", "GA") 关键字 IN (可以包含若干个 OR) # WHERE state NOT IN ("VA", "FL", "GA") */ /* Return products with quantity in stock equal to 49, 38, 72 */ /* SELECT * FROM products WHERE quantity_in_stock IN (49, 38, 72) */ /* Return customers born between 1/1/1990 and 1/1/2000 */ /* SELECT * FROM customers WHERE birth_date BETWEEN "1990-01-01" AND "2000-01-01" # 关键字 (BETWEEN) 代替 >= AND <= # WHERE birth_date >= "1990-01-01" AND birth_date <= "2000-01-01" */ /* SELECT * FROM customers WHERE last_name LIKE "b%_y" # % any number of characters # _ single characters # 关键字 (LIKE) */ /* Get the customers whose addresses contain TRAIL or AVENUE hone numbers end with 9 */ /* SELECT * FROM customers WHERE address LIKE "%trail%" OR address LIKE "%avenue%"; SELECT * FROM customers WHERE phone LIKE "%9"; SELECT * FROM customers WHERE phone NOT LIKE "%9"; */ /* SELECT * FROM customers WHERE lats_name REGEXP "[a-h]e"*/ /* -- ^ begining "%f" -- $ end "f%" -- | or "ni | ss | qq" -- [abc]f "af | bf | cf" -- [a-c]f "af | bf | cf" -- "as" just contains "as" "%as%" */ /* Ger the customers whose first name are ELKA or AMBUR last names end with RY or ON last name start with MY or contains SE last name contain B followed by R or U */ SELECT * FROM customers WHERE first_name IN("ELKA", "AMBUR"); SELECT * FROM customers WHERE last_name REGEXP "EY$|ON$"; SELECT * FROM customers WHERE last_name REGEXP "^MY|SE"; SELECT * FROM customers WHERE last_name REGEXP "B[ru]";
这篇关于Mysql笔记的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-15MySQL教程:初学者必备的MySQL数据库入门指南
- 2024-11-15MySQL教程:初学者必看的MySQL入门指南
- 2024-11-04部署MySQL集群项目实战:新手入门教程
- 2024-11-04如何部署MySQL集群资料:新手入门指南
- 2024-11-02MySQL集群项目实战:新手入门指南
- 2024-11-02初学者指南:部署MySQL集群资料
- 2024-11-01部署MySQL集群教程:新手入门指南
- 2024-11-01如何部署MySQL集群:新手入门教程