我有一个下面的表格
表1
from scipy import stats
import numpy as np
arr = np.array([4, 4, 1, 6, 6, 8, 1, 2, 3, 2, 2, 3, 4, 7, 6, 8, 0, 2, 8, 6, 5])
alpha = 0.05 # significance level = 5%
df = len(arr) - 1 # degress of freedom = 20
t = stats.t.ppf(1 - alpha/2, df) # 95% confidence t-score = 2.086
s = np.std(arr, ddof=1) # sample standard deviation = 2.502
n = len(arr)
lower = np.mean(arr) - (t * s / np.sqrt(n))
upper = np.mean(arr) + (t * s / np.sqrt(n))
print((lower, upper))
>>> (3.0514065531195387, 5.329545827832843)
print(stats.t.interval(1 - alpha/2, df, loc=np.mean(arr), scale=s / np.sqrt(n)))
>>> (2.8672993716475763, 5.513653009304806)
表2
Id | Name | Date
1 A 11.12.2018
2 B 12.12.2018
3 C 13.01.2017
4 D 15.06.2019
5 E 21.05.2019
我想选择所有标记大于80的记录,并且我想显示所有选定记录的max(date)。预期输出应该像
Id | Marks
1 50
2 79
3 90
4 95
5 92
由于我是sql和teradata的新手,因此略有障碍。感谢您的时间和帮助
谢谢。
这是我很累的查询,
Id | Name | Date
3 C 15.06.2019
4 D 15.06.2019
5 E 15.06.2019
答案 0 :(得分:1)
将MAX
用作整个表的分析函数,并更正联接语法:
SELECT
a.Id,
a.name,
MAX(a.date) OVER () AS max_date
FROM Table1 a
INNER JOIN Table2 b
ON a.Id = b.Id
WHERE
b.Marks > 80;
上述方法的替代方法是使用子查询在整个表中查找最大日期:
SELECT
a.Id,
a.name,
(SELECT MAX(a.date)
FROM Table1 a INNER JOIN Table2 b ON a.Id = b.id
WHERE b.Marks > 80) AS max_date
FROM Table1 a
INNER JOIN Table2 b
ON a.Id = b.Id
WHERE
b.Marks > 80;