Data type
发表于|更新于|notes
|总字数:0|阅读时长:1分钟|浏览量:
文章作者: Yuki-I-Rain
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Yuki-I-Rain!
相关推荐
2025-06-16
Distinguish having and where
WHERE HAVING 执行时机 分组前过滤 分组后过滤 使用对象 原始表中的列 分组结果或聚合函数计算结果 性能 通常更高效 通常效率较低 1234SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 5000; -- 不能用WHERE过滤聚合结果 1234SELECT product_id, COUNT(*) as order_countFROM ordersGROUP BY product_idHAVING order_count > 10; -- 过滤分组后的计数结果 1234SELECT customer_id, SUM(amount) as total_spentFROM transactionsGROUP BY customer_idHAVING total_spent > 1000; -- WHERE不能使用别名 使用建议 优先使用WHERE:能在WHERE中完成的条件就不要用HAVIN...
2025-06-05
Union
Basic Sentence123SELECT column_name(s) FROM table_name1UNIONSELECT column_name(s) FROM table_name2 The SELECT statements within a UNION must have the same number of columns. Columns must also have similar data types. Meanwhile, the order of the columns in each SELECT statement must be the same. SELECT will automatic deduplication, while SELECT ALL will not. UNIONTables: employees: emp_id name dpt_id 1 apple 101 2 boy 102 3 cat 101 4 dog 103 former_employees: emp_id name d...
2025-06-04
Join(two tables)
Basic sentence1234SELECT columnsFROM table1() JOIN table2ON table1.column_name=table2.column_name; INNER JOININNER JOIN equals to JOIN, Explicit form 1INNER JOIN Implicit form 1JOIN Tables :Person : personID lastName firstName 1 Wang Allen 2 Alice Bob Address: addressID personID city state 1 2 New York City New York 2 3 Leetcode California 1234SELECT Person.firstName, Address.cityFROM PersonINNER JOIN AddressON Person.personID = Address.personID; result: firstName...
2025-06-15
Regular Expression
一般形式1WHERE example_column REGEXP '这里写正则表达式内容' 注意: 要加引号 默认情况不区分大小写 若要区分,则使用 1REGEXP BINARY 基本用法^ 表示字符串开始 e.g. ^e表示以e开始 注意:若^在[]里面,则表示取补集 e.g. [^a]表示除了a以外的所有字母 $表示字符串结束 e.g.x$表示以x结束 []表示 character set,结合-使用表示范围, e.g: [1-9]表示1,2,3,4,5….8,9组成的集合 [cde]表示c,d,e中的一个字符 {}为数量符,匹配前一个字符的数量 e.g: [0-9]{2}表示2个0-9中的任意字符 e{3,5}表示至少3个,至多5个e ?为数量符,匹配前一个字符1次或0次 e.g. -?表示搜寻’0个或者1个字符 “-“ +为数量符,匹配前一个字符至少1次 e.g. 3[a-z]+4表示3与4之间有至少一个字母 *为数量符,匹配前一个字符0次或多次(包括1次) .等价于占位符,匹配(除了换行符外的)单个字符 |表...
公告
Welcome to my blog~