-- sql server -- spt_values select * from master.dbo.spt_values where Type='PSELECT a.Type, a.Num, b.number,1 Num
FROM F0519 a
JOIN master.dbo.spt_values b
ON b.Type='P'AND a.Num>b.Number
-- mysql/*
help_topic本身是Mysql一个帮助解释注释表,用于解释Mysql各种专有名词,由于这张表数据ID是从0顺序增加的,方便我们用于计数,但是8.0.17版本的只有686条数据,超过这个数字,我们就需要己自定义一张表。
可以用做计数的临时表,查询的语句只会用help_topic计数,超出的部分其实都是脏数据
*/SELECT a.type,1as num
FROM F0519 a
JOIN mysql.help_topic b
on b.help_topic_id < a.Num;
WITH CTE AS(SELECT*,
ROW_NUMBER()OVER(PARTITIONBY OprSeq ORDERBY TransTime) RN
FROM F0524
)SELECT
a.OprSeq,
a.OpCode,
a.TransTime AS StartTime,
b.TransTime AS EndTime
FROM CTE a
LEFTJOIN CTE b
ON a.OprSeq=b.OprSeq AND b.RN=a.RN+1WHERE a.RN %2>0;
SELECT CUSTOMER_ID
FROM(SELECT
CUSTOMER_ID,
RANK()OVER(ORDERBY T DESC) R
FROM(SELECT CUSTOMER_ID,COUNT(1) T
FROM F0531
GROUPBY CUSTOMER_ID
) A
) B
WHERE B.R=1;
七、数据拼接
CREATETABLE F0609A (
A INT,
B INT);INSERTINTO F0609A VALUES(1,2);INSERTINTO F0609A VALUES(4,6);CREATETABLE F0609B (
C INT,
D INT,
E INT);INSERTINTO F0609B VALUES(7,4,3);INSERTINTO F0609B VALUES(9,5,8);INSERTINTO F0609B VALUES(11,15,18);-- 要求:将F0609A里的数据与F0609B里的数据进行拼接,得到如下图所示结果。
SELECT A1.A, A1.B, B1.C, B1.D, B1.E
FROM(SELECT ROW_NUMBER()OVER(ORDERBY a) id, A, B
FROM F0609A T1
) A1
FULLJOIN(SELECT ROW_NUMBER()OVER(ORDERBY C) id, C, D, E
FROM F0609B T2
) B1
ON A1.id=B1.id
-- 方法一 SELECT ID
FROM F0613 a
WHERE a.temp>(SELECTtempFROM F0613 b
WHERE a.ID = b.ID +1)-- 方法二 SELECT f2.ID
FROM F0613 f1,F0613 f2
WHERE DATEDIFF(DAY,f1.ReDate,f2.ReDate)=1AND f2.Temp> f1.Temp