![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
SQL
SQL
Loong Tu
这个作者很懒,什么都没留下…
展开
-
13. 创建和操纵表
文章目录创建表创建表CREATE TABLE products_test ( prod_id char(10) NOT NULL, vend_id char(10) NOT NULL, prod_name char(255) NOT NULL, prod_price decima...原创 2020-02-28 18:25:49 · 95 阅读 · 0 评论 -
12. 更新和删除数据
文章目录本节使用的表customers更新数据删除数据本节使用的表customerspostgres=# \d customers Table "public.customers" Column | Type | Collation | Nullable | Default--------------+------...原创 2020-02-23 22:59:47 · 174 阅读 · 0 评论 -
11. 插入数据
文章目录本节使用的表customers插入完整的行本节使用的表customerspostgres=# \d customers Table "public.customers" Column | Type | Collation | Nullable | Default--------------+--------...原创 2020-02-21 23:06:39 · 148 阅读 · 0 评论 -
10. 组合查询
文章目录本节使用的表customers定义创建组合查询单条语句多个WHEREUNION包含重复的行对组合查询结果排序UNION规则本节使用的表customerspostgres=# \d customers Table "public.customers" Column | Type | Collation | Nu...原创 2020-02-20 23:07:20 · 135 阅读 · 0 评论 -
9. 创建高级联结
文章目录本节使用的表vendorsproductscustomersordersorderitems使用表别名自联结子查询的方法自联结的方法本节使用的表vendorspostgres=# \d vendors Table "public.vendors" Column | Type | Collation | Null...原创 2020-02-14 22:43:24 · 100 阅读 · 0 评论 -
8. 联结表
文章目录postgres=# \d vendors Table "public.vendors" Column | Type | Collation | Nullable | Default--------------+---------------+-----------+----------+--------- ve...原创 2020-02-10 20:20:17 · 187 阅读 · 0 评论 -
7. 使用子查询
文章目录利用子查询进行过滤作为计算字段使用子查询利用子查询进行过滤select order_numfrom orderitemswhere prod_id = 'RGAN01'; order_num----------- 20007 20008(2 rows)select cust_idfrom orderswhere order_num in (200...原创 2020-02-03 21:51:50 · 92 阅读 · 0 评论 -
6. 分组数据
分组数据创建分组过滤分组分组和排序SELECT子句顺序创建分组select vend_idfrom products; vend_id------------ BRS01 BRS01 BRS01 DLL01 DLL01 DLL01 DLL01 FNG01 FNG01(9 rows)select vend_idfrom productsgroup by v...原创 2019-09-08 23:12:17 · 113 阅读 · 0 评论 -
5. 汇总数据
汇总数据聚集函数AVG()函数COUNT()函数MAX()和MIN()函数聚集函数函数说明AVG()返回某列的平均值COUNT()返回某列的行数MAX()返回某列的最大值MIN()返回某列的最小值SUM()返回某列值之和AVG()函数AVG()函数忽略列值为NULL的行。select avg(prod_price) as avg_...原创 2019-09-08 20:45:37 · 146 阅读 · 0 评论 -
4. 使用函数处理数据
使用函数处理数据文本处理函数日期和时间处理函数数值处理函数文本处理函数常用的文本处理函数:函数说明备注LEFT()返回字符串左边的字符或使用子字符串函数LENGTH()返回字符串的长度也使用DATALENGTH()或len()LOWER()将字符串转换为小写LTRIM()去掉字符串左边的空格RIGHT()返回字符串右边的字符或...原创 2019-09-08 17:47:45 · 114 阅读 · 0 评论 -
3. 创建计算字段
创建计算字段拼接字段postgres=# select *postgres-# from vendors; vend_id | vend_name | vend_address | vend_city | vend_state | vend_zip | vend_country------------+-----------------...原创 2019-09-08 15:43:23 · 172 阅读 · 0 评论 -
2. 过滤数据
过滤数据空值检查组合where子句IN操作符NOT操作符通配符空值检查select cust_name, cust_emailfrom customerswhere cust_email is null; cust_name | cust_email---------------------------...原创 2019-09-08 15:10:23 · 146 阅读 · 0 评论 -
1. 检索数据
postgres=# \d products Table "public.products" Column | Type | Collation | Nullable | Default------------+-------------------------+-----------+------...原创 2019-09-08 14:52:53 · 147 阅读 · 0 评论