在Databricks中,如何以升序/降序的方式显示PySpark中的日期:

huangapple go评论68阅读模式
英文:

How to display date in PySpark in descending/ascending order in Databricks

问题

我尝试显示以下查询的结果以升序/降序排列。然而,我不确定在哪里放置DES或ASC子句。

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date()), -2))""")

所以,我想知道在上面的代码中放置des或asc以获取按日期降序或升序显示的输出。

我尝试了以下内容:

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date() DES), -2))""")

但我得到了语法错误。

英文:

I am trying to display the results from the following query in ascending/descending order. However, I'm not sure where to place the DES or ASC clause.

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date()), -2))""")

So, I would like to know where to place the des or asc in the above code to get date output shown in descending or ascending order?

I tried the following

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date() DES), -2))""")

But I got a syntax error

答案1

得分: 1

尝试在where子句后面添加order by子句。

示例:

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date()), -2)) order by date asc""")
英文:

Try by adding order by clause after the where clause.

Example:

df = sql("""select * from myview
where date = last_day(add_months(date_trunc("month", current_date()), -2)) order by date asc""")

huangapple
  • 本文由 发表于 2023年6月18日 23:19:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定