简体   繁体   中英

Where clause missing in SQL Query

I am sending a SQL query from a client to a MySQL database. When I run the query in MySQL the result is correct.

The result from the query is wrong, when sent from client. The last WHERE clause is missing.

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)

In the MySQL Query log the query 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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