【问题标题】:What is the correct ORDER BY syntax in DataJoint for Python?DataJoint for Python 中正确的 ORDER BY 语法是什么?
【发布时间】:2018-08-17 21:15:46
【问题描述】:

在 Python 的 DataJoint 中,fetch 命令中使用的 ORDER BY 参数的正确语法是什么?

current documentation(截至 2018-08-17)仅在 MATLAB 中为 DataJoint 指定以下语法:

s = fetch(experiment.Session, '*', 'ORDER BY session_date DESC LIMIT 5')

【问题讨论】:

    标签: python database open-source datajoint


    【解决方案1】:

    在 Python 中,ORDER BY 参数的正确语法是

    table.fetch(order_by='attr')
    

    如果您需要按多个属性排序,请将它们作为元组提供:

    table.fetch(order_by=('attr1', 'attr2'))
    

    这将根据指定的属性按升序对获取的项目进行排序。要使其降序,请将单词 DESC 添加到属性中。

    table.fetch(order_by='attr DESC')
    table.fetch(order_by=('attr1 DESC', 'attr2'))
    

    您也可以选择使用单词ASC 来隐含升序,但省略它具有相同的效果。

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 2018-12-03
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多