英文:
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""")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论