ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Mysql笔记

2022-01-25 12:33:59  阅读:180  来源: 互联网

标签:customers 01 name price 笔记 Mysql WHERE SELECT


/*
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]";

 

  

标签:customers,01,name,price,笔记,Mysql,WHERE,SELECT
来源: https://www.cnblogs.com/SSummerZzz/p/15842454.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有