官术网_书友最值得收藏!

Using SQL subqueries

It is also possible to use subqueries in ApacheSparkSQL. In the following example, a SQL query uses an anonymous inner query in order to run aggregations on Windows. The encapsulating query is making use of the virtual/temporal result of the inner query, basically removing empty columns:

val result = spark.sql("""
SELECT * from (
SELECT
min(temperature) over w as min_temperature,
max(temperature) over w as max_temperature,
min(voltage) over w as min_voltage,
max(voltage) over w as max_voltage,
min(flowrate) over w as min_flowrate,
max(flowrate) over w as max_flowrate,
min(frequency) over w as min_frequency,
max(frequency) over w as max_frequency,
min(hardness) over w as min_hardness,
max(hardness) over w as max_hardness,
min(speed) over w as min_speed,
max(speed) over w as max_speed
FROM washing_flat
WINDOW w AS (ORDER BY ts ROWS BETWEEN CURRENT ROW AND 10 FOLLOWING)
)
WHERE min_temperature is not null
AND max_temperature is not null
AND min_voltage is not null
AND max_voltage is not null
AND min_flowrate is not null
AND max_flowrate is not null
AND min_frequency is not null
AND max_frequency is not null
AND min_hardness is not null
AND min_speed is not null
AND max_speed is not null
""")

The result of the subqueries is as follows:

主站蜘蛛池模板: 宽城| 深泽县| 定安县| 武功县| 喜德县| 齐河县| 宜州市| 随州市| 闻喜县| 平罗县| 全州县| 扶风县| 百色市| 阳曲县| 玉林市| 广安市| 沙田区| 泸定县| 平武县| 贵阳市| 庆云县| 台北县| 汉阴县| 烟台市| 阳原县| 南阳市| 界首市| 绥中县| 江门市| 清水河县| 铜川市| 龙川县| 连州市| 宁陵县| 睢宁县| 勐海县| 合山市| 中牟县| 隆德县| 万盛区| 泸州市|