SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO;
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE AMOUNT>=900.00
=【等于】
!=、<>【不等于】
>【大于】
<【小于】
>=【大于等于】
<=【小于等于】
Like【not like】;in【not in】;between...and【not between...and】;is null【not is null】
Like【模糊查询】
_:代表一个字符;
%:代表任意个字符
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE AUTHORCODE like '32%'
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE AUTHORCODE like '3_2%';
IN【匹配查询】
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE FEE in (9.00,4.00)
between...and...【区间查询】要为小写
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE FEE between 1.00 and 2.00
4:逻辑筛选
And;or;not
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE FEE>= 1.00 and FEE<=2.00
SELECT
THIRDSYSTIME AS 交易时间,AMOUNT AS 交易金额,AUTHORCODE AS 交易码, FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM T_CPS_CUPSICACINFO
WHERE FEE>= 9.00 or FEE<=1.00
SELECT
FEE AS 手续费,count(FEE) AS 总数,avg(AMOUNT) AS 平均交易金额
FROM T_CPS_CUPSICACINFO
group by FEE
SELECT
FEE AS 手续费,count(FEE) AS 总数,avg(AMOUNT) AS 平均交易金额
FROM T_CPS_CUPSICACINFO where FEE>=5.00
group by FEE
SELECT
FEE AS 手续费,count(FEE) AS 总数,avg(AMOUNT) AS 平均交易金额
FROM T_CPS_CUPSICACINFO where FEE>=5.00
group by FEE having avg(AMOUNT)>500.00
注意:where;group by;having的执行顺序
Where用于筛选有from指定的数据对象;
Group by 用于对where或from的结果进行分组
Having是对group by的分组数据再进行过滤
With rollup 函数
SELECT
FEE AS 手续费,count(FEE) AS 总数,avg(AMOUNT) AS 平均交易金额
FROM T_CPS_CUPSICACINFO
group by FEE with rollup
Order by desc【降序】
SELECT
FEE AS 手续费,count(FEE) AS 总数,avg(AMOUNT) AS 平均交易金额
FROM T_CPS_CUPSICACINFO where fee>=5.00
group by FEE order by FEE desc
Sum【求和】
Avg【平均值】
Max【最大值】
Min【最小值】
子查询的使用地方相当多,在select,insert,update,delete命令中允许是一个表达式的地方都可以包含子查询
以分页查询为例:
SELECT THIRDSYSTIME AS 交易时间, AMOUNT AS 交易金额,FEE AS 手续费,SYSSERNO AS 系统跟踪号
FROM
(SELECT T_CPS.*,ROWNUMBER() OVER() AS RNUM FROM
(SELECT * FROM T_CPS_CUPSICACINFO) AS T_CPS) AS A
WHERE
A.RNUM BETWEEN 10 AND 20;