问题标签 [select-query]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2696 浏览

android - 在android的SQLite中编译select语句时没有这样的列错误

/数据库创建代码/

/数据检索代码/

}

/* LOGCAT */

0 投票
2 回答
1620 浏览

sql - 使用 MS Access 数据库的尾随十二个月公式

我有一个名为的数据库Cash_Flow_Statements,我需要创建一个已保存的查询来计算过去十二个月 (TTM) 的自由现金流。

这是我的数据库的示例:

现金流量表

这是我保存的查询的代码。我已将此代码用于其他计算,所以我知道它有效。我只是不知道如何在 SQL 中执行尾随十二个月。

我需要该变量Formula包含将计算过去 12 个月的自由现金流的等式。这是数学的样子:

自由现金流 TTM = 总和(营运现金流 MRQ1 + 营运现金流 MRQ2 + 营运现金流 MRQ3 + 营运现金流 MRQ4) - 总和(资本支出 MRQ1 + 资本支出 MRQ2 + 资本支出 MRQ3 + 资本支出 MRQ4)

MRQ = 最近一个季度

我需要这个公式在 SQL 中。我该怎么做呢?

更新

根据@Gord Thompson 在下面的回答,我提出了以下代码:

当它自己运行时,它会返回我所需要的。但正如我在原始帖子中提到的,我需要能够设置变量Formula以包含 SQL 语句,然后将其插入现有的 SQL 语句中。

所以我试图适应@Gord Thompson 的回答,我想出了这个。

公式:

SQL 语句:

这是结果:

在此处输入图像描述

同样,这非常接近,但不是我需要的。我相信我知道是什么导致代码在调整时无法工作,但我还不知道如何修复它。在@Gord Thompson 代码中,最后一行是FROM Cash_Flow_Statements AS s. 当我将变量公式插入原始帖子中的现有 SQL 语句时,代码为FROM (Income_Statements AS Income_Statements _ INNER JOIN Balance_Sheets AS Balance_Sheets ON (Income_Statements.Ticker = Balance_Sheets.Ticker) AND (Income_Statements.[Year] = Balance_Sheets.[Year]) AND (Income_Statements.Period = Balance_Sheets.Period)) _ INNER JOIN Cash_Flow_Statements AS Cash_Flow_Statements ON (Balance_Sheets.Ticker = Cash_Flow_Statements.Ticker) AND (Balance_Sheets.[Year] = Cash_Flow_Statements.[Year]) AND (Balance_Sheets.Period = Cash_Flow_Statements.Period). 我几乎可以肯定这就是问题所在,但不知道如何纠正它。

0 投票
2 回答
833 浏览

sql - 让 SELECT 在单个 SQL 查询中的 NULL 和 EMPTY 行的两种情况下都返回零

以下查询结果值作为单行作为值ExtendedText或零用于匹配LineNumber表数据。我需要在查询中再添加一个条件 - 如果LineNumber不存在则返回一行为零,与 null 的情况相同。查询应同时检查是否为NULL空以返回零

0 投票
3 回答
652 浏览

database - 将 sql 结果作为单个字符串返回

我有以下查询返回超过 1 个结果(最多大约 10 行而不是更多!),如何将所有结果作为单个字符串返回?

已尝试使用STUFF如下但它不起作用:

0 投票
0 回答
241 浏览

sql - 满足第一个条件后 MS Access 切换查询未结束

我正在尝试在 MS Access 中运行一个选择查询,其被评估的值满足多个条件(即:日期范围)。以下查询的结果包含重复项,因为即使在满足第一个语句之后,该语句也会继续评估。我在这个陈述中做错了什么,或者这不是正确的陈述?我尝试过使用 iif 语句,但它们也有相同的结果。

0 投票
1 回答
1757 浏览

java - PostgreSQL negate a numeric value in resultset

I have a query to return a resultset of decimal(30,12) type data.

This query is giving me output like this:

But I need an output as follow:

0 投票
3 回答
1030 浏览

mysql - 如果我们需要在jsp中查询一个id数组,如何查询数据库?

在选择了一些产品后,用户点击了继续按钮。现在我需要在下一页显示选定的数据。我使用以下代码成功获取了所选数据的 ID。

现在我需要使用“select * from table where id=?”来查询 mysql 数据库。我可以循环使用这个查询。但是有没有其他或更好的方法来做到这一点?

0 投票
1 回答
87 浏览

php - sql query that would return a table, and count other tables relevant to the results of the first

I'm trying to write a forum for a school project, and I'm still struggling with some queries. So, basically I have the following tables:

  1. forums (forum_id,forum_title,forum_description)
  2. topics (topic_id,forum_id(the forum that it belongs to), topic_content...etc)
  3. posts (post_id, topic_id(the topic that it belongs to)...etc)

What I need is a query that would display all the forums in the main page + count all the topics and add it alongside the relevant forum AND also count all the posts that belong to all the topics that belong to the relevant forum.

This is what I came up with so far:

For some reason, this query returns rather peculiar values. When there's one topic and no posts that belong to this topic, it correctly returns 1 for topics and 0 for posts. However, when I add more relevant posts, it increases the number of topics as well. Basically, it equates the number of topics to the number of posts so I always get x topics and x posts if post is greater than 0.

Any ideas?

0 投票
2 回答
97 浏览

php - Mysql select 查询 nut 完全运行

我有以下查询:

但我收到以下错误:

他们so的数据库是 Oracle,该KI表有 2700000 条记录。

非常感谢任何帮助!我想知道为什么会出现这样的错误!

0 投票
1 回答
761 浏览

mysql - 从两个表中选择 MAX 值:哪个更好

我有两种方法可以从两个表中选择 MAX 值,但不知道哪一个更好或更快。我检查过,mysql workbench但如果两个查询我都得到0.00 Sec执行时间

第一次查询

解释 在此处输入图像描述

第二次查询

解释 在此处输入图像描述 所以问题是哪一个在速度方面更好?