简体   繁体   English

SQL 查询中缺少 Where 子句

[英]Where clause missing in SQL Query

I am sending a SQL query from a client to a MySQL database.我正在从客户端向 MySQL 数据库发送 SQL 查询。 When I run the query in MySQL the result is correct.当我在 MySQL 中运行查询时,结果是正确的。

The result from the query is wrong, when sent from client.从客户端发送时,查询的结果是错误的。 The last WHERE clause is missing.缺少最后一个 WHERE 子句。

The query original looks like this:查询原文如下所示:

SELECT SUM(Second_In_State) From 
(SELECT 
    Time_Stamp, 
    State,
    TIMESTAMPDIFF(SECOND, LAG(Time_Stamp) OVER(ORDER BY Time_Stamp), Time_Stamp)
AS Second_In_State
FROM db.xyz_1_state
ORDER BY Time_Stamp) AS T
Where State = 1;

Result is number of seconds where State = 1 (The wanted result)结果是 State = 1 的秒数(想要的结果)

In the MySQL Query log the query looks like this:在 MySQL 查询日志中,查询如下所示:

SELECT SUM(Second_In_State) From 
(SELECT 
    Time_Stamp, 
    State,
    TIMESTAMPDIFF(SECOND, LAG(Time_Stamp) OVER(ORDER BY Time_Stamp), Time_Stamp)
AS Second_In_State
FROM db.xyz_1_state
ORDER BY Time_Stamp) AS T

The result is the total of seconds in all states.结果是所有状态的总秒数。 (Wrong result) (错误的结果)

Any suggestions why the last line is missing?有什么建议为什么缺少最后一行?

Thanks for your comments.感谢您的意见。

I found out that the client is limited in number of lines.我发现客户端的行数有限。 So when saving the last line is deleted.所以保存时最后一行被删除。

So converting the query to a single line, solved the problem.所以将查询转换为单行,解决了这个问题。

Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM