如何将2个条件合并为1行SQLite?

时间:2017-09-06 08:55:31

标签: sqlite

我尝试使用AND但它没有工作
这是原始代码

getAllFeeds(user_id_fk, start) {
  let data = [user_id_fk, start]

// ---------this part here ------------------------------------------------------------
  return this.database.executeSql("SELECT * FROM feed WHERE (user_id_fk) = (?) ORDER BY feed_id DESC LIMIT ?, 5", data).then((data) => {
// ------------------------------------------------------------------------------------    

  let feeds = [];
    if (data.rows.length > 0) {
      for (var i = 0; i < data.rows.length; i++) {
        feeds.push({ feed_id: data.rows.item(i).feed_id, feed: data.rows.item(i).feed, user_id_fk: data.rows.item(i).user_id_fk, created: data.rows.item(i).created });
      }
    }
    return feeds;
  }, err => {
    console.log('Error: ', err);
    return [];
  });
}

如何添加此内容?

SELECT DATETIME(created, '+8 hours') as `add8hours` FROM feed WHERE (user_id_fk) = (?) ORDER BY feed_id DESC;

当我使用最后一行时,结果将只显示日期时间而不显示其他列 这是表BTW

CREATE TABLE IF NOT EXISTS feed (
feed_id INTEGER PRIMARY KEY AUTOINCREMENT,
feed TEXT,
user_id_fk INTEGER,
created DATETIME DEFAULT CURRENT_TIMESTAMP
);

1 个答案:

答案 0 :(得分:0)

如果要显示表中的某些特定列,则需要用逗号分隔它们。 例如(使用别名):SELECT COLUMN_1_NAME as ALIAS_COLUMN_1, COLUMN_2_NAME as ALIAS_COLUMN_2 FROM TABLE_NAME;

所以在你的情况下它应该是这样的:

SELECT DATETIME(created, '+8 hours') as add8hours, feed FROM feed WHERE (user_id_fk) = (?) ORDER BY feed_id DESC LIMIT ?, 5