Postagesql 浅入
创建table
创建table創建datebase test
CREATE DATEBASE <test>;刪除database test
DROP DATEBASE <test>;創建table test;
CREATE TABLE <table_name>;刪除table preson;
DROP TABLE preson;創建表名/表內容;
CREATE TABLE person1 (
id BIGSERIAL not null primary key,
first_name VARCHAR(50) not null,
last_name VARCHAR(50) not null,
gender VARCHAR(50) not null,
date_of_birth date not null,
email VARCHAR(150)
);
創建表內容;
查看表
查看表内容
查看表内容查看person(table)中first_name(column)内容
用法
升序/降序 ASC/DESC
ASC/DESCDISTINCT 去重
DISTINCT 去重Where 查找
Where 查找Where Clause and AND
通过where gender 'female'查找表中女性. where and运用
查找女性,China在table person2;
where and or
查找女性,China和Panama在table person2;
where and or and 和 /或/和
查找女性,China和Panama在table person2的Tritton;
Comparison Operators
Comparison Operators<>不等于
limit & offset & IN
limit & offset & INLIMIT 至少だけ のみ
OFFSET 第几行开始/跳过前几行
offset 5 跳过前5行,fetch FIRST 5 row only; 只返回接下来五行结果.
IN
使用 WHERE OR、如果使用IN
使用IN也可以完成这样的OR查找
Between & Like
Between & LikeBetween 区间
order by x; 按照什么 排序;
Like and iLike
查看email中com的邮箱
携带a的邮箱
______@%@前面6个字符
Group
Groupgroup
两者都可以列出table中country_of_birth;
count(*) 计数
count(*) 计数group by having
group by havinghaving count(*) > 5
最终显示 count(*) > 5 的国家
Adding New Table And Data Using Mockaroo
https://www.mockaroo.com 使用这个网站我们可以创建一些table来便于我们体会到这些用法.
Input table 导入表
Input table 导入表导入car.sql path为你的路径
MAX & MIN & AVG & SUM & ROUND()
MAX & MIN & AVG & SUM & ROUND()Max 最大 用法
Min 最小 用法同理
avg 平均值
sum 求和
round()四舍五入 整数
查看每一组品牌+型号 最低价格
运算
运算price 乘以 0.10(也就是 10%),返回直
查询所有汽车的信息,并计算每辆车“价格的 10%,保留两位小数”,显示值
原价减 10% 后的价格(打 9 折),并四舍五入到整数。
例子:
price = 20000:
10% 是 2000
price - 10% = 18000
ROUND(18000) = 18000
id
ID
make
品牌
model
型号
price
原价
round(price * 0.10, 2)
原价的 10%
round(price - price*0.10, 2)
打 9 折后的价格
Alias
coalesce
NULL IF
NOW()
NOW()sql时间
NOW()DATE;
NOW()::time;
Now()减去一年时间
Last updated
Was this helpful?