相关疑难解决方法(0)

PostgreSQL按日期时间asc排序,先是null吗?

我需要按日期/时间字段对PostgreSQL表进行排序,例如last_updated.

但是,该字段允许为空或空,我想与空记录last_updated之前,非空last_updated.
这可能吗?

order by last_updated asc /* and null last_updated records first ?? */
Run Code Online (Sandbox Code Playgroud)

sql postgresql null sql-order-by

69
推荐指数
2
解决办法
4万
查看次数

DESC 中的订单记录在 SequelizeJS 中不起作用

在我的应用程序中,我有 Products 表,其中包含各种类型的产品。在每条记录中都有列调用updateDetails,它是一个JSON具有以下属性的对象。

const updateDetails = { time: '2020-05-28T05:53:31.540Z', userId: 1, officeId: 2}
Run Code Online (Sandbox Code Playgroud)

但在产品表中的一些记录updateDetailsnull,将任何用户编辑的记录后更新。

我的示例数据库记录如下。

[
 { 
  name: 'Product 1', 
  type: 'a', 
  updateDetails: { time: '2020-05-28T05:53:31.540Z', userId: 1, officeId: 2 }
 },
 { 
  name: 'Product 2', 
  type: 'a', 
  updateDetails: null
 },
 { 
  name: 'Product 3', 
  type: 'a', 
  updateDetails: { time: '2020-05-27T05:53:31.540Z', userId: 1, officeId: 2 }
 },
 { 
  name: 'Product 4', 
  type: 'a', 
  updateDetails: null
 },
 { 
  name: 'Product 5', 
  type: 'a', …
Run Code Online (Sandbox Code Playgroud)

javascript postgresql node.js express sequelize.js

8
推荐指数
0
解决办法
208
查看次数

JPA条件API最后按NULL顺序排序

我使用JPA标准API从日期库中获取记录.我有实体记录,字段dateTime可以为null.我会编码:

public List<Record> find(RecordFilter recordFilter, int page, int pageSize) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Record> criteriaQuery = criteriaBuilder.createQuery(Record.class);
    Root<Record> recordRoot = criteriaQuery.from(Record.class);

    /*
     * JOINS. Left Joins are used for optional fields, or fields inside of the optional fields.
     */
    Join<Record, Agency> recordAgencyJoin = recordRoot.join(RecordTable.FIELD_AGENCY);
    //Some other joins

    //This is where I had the problem. 
    applyOrderBy(criteriaQuery, criteriaBuilder, recordRoot);

    /*
     * Specify which columns to select and their order.
     * criteriaQuery.multiselect(....);
     */              
    applyMultiSelect(recordRoot, recordAgencyJoin, /*other joins*/ criteriaQuery); …
Run Code Online (Sandbox Code Playgroud)

java jpa criteria-api

4
推荐指数
1
解决办法
1万
查看次数