英文:
how to get dates sorted in ascending order from influx db query, right now its in string format
问题
我有一个查询
SELECT last("date_of_maturity") FROM "maturity_date_data" GROUP BY "maturity";
我得到这些值
010423
020423
070423
140423
260523
280423
290923
291223
300623
310323
该字段是字符串格式,但值是日期。
需要按日期顺序输出。
英文:
I have a query
SELECT last("date_of_maturity") FROM "maturity_date_data" GROUP BY "maturity";
Im getting this values
010423
020423
070423
140423
260523
280423
290923
291223
300623
310323
The field is string format, but the values are dates.
Need output arranged datewise.
答案1
得分: 1
只返回翻译好的部分:
将您的字符串日期转换为实际日期,并按日期排序:
```sql
SELECT last("date_of_maturity") dom
FROM "maturity_date_data"
GROUP BY "maturity";
ORDER BY to_date(dom, 'ddMMyy') asc
英文:
You could to convert your string date to actual date, and order by it:
SELECT last("date_of_maturity") dom
FROM "maturity_date_data"
GROUP BY "maturity";
ORDER BY to_date(dom, 'ddMMyy') asc
答案2
得分: 0
如果这是一个Python问题,它与influxdb
、grafana
或regex
(你的标签)无关。问题变成了:如何按照日期格式DDMMYY对日期列表进行按时间顺序排序?答案是一个Python一行代码,如果你假设日期以6位数字字符串的形式存储在名为results
的列表中:
results.sort(key=lambda x: x[4:6]+x[2:4]+x[0:2])
英文:
If this is a python question, it has nothing to do with influxdb
or grafana
or regex
(your tags). The question becomes: How do I sort a list of dates in the format DDMMYY in chronological order? The answer is a python one liner, if you assume the dates are in a list of 6-digit strings in a list called: results
:
results.sort(key=lambda x: x[4:6]+x[2:4]+x[0:2])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论