You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bob M <rg...@orcon.net.nz> on 2016/04/05 07:45:14 UTC

Processing a subset of records correctly

I have just realized that I am processing the subset in reverse order (i.e.
latest date backwards)

I want to process in earliest date forwards direction

The subset should consist of 102 records
I ignore the most recent
I look at the earliest - and record the prediction only
For the rest I record the current class and compare it with the prediction
from the previous record

My code is as follows:-

try
{
rs = s.executeQuery("SELECT * FROM xxx WHERE TRADE_NO <>0 ORDER BY
Trading_Date DESC,"
        + " Trading_Time DESC FETCH NEXT 101 ROWS ONLY");
// myConsole.getOut().println("Successfully retrieved 101 records from xxx
table: ");

int k = 0;
while (k < 100) {
// for k = 0 record, just get predictions
rs.next();
String Date5 = rs.getString("Trading_Date");
int Time5 = rs.getInt("Trading_Time");

if (k < 1) {
pred_test1 = rs.getString("Class1_Predicted");

if (j == 0) { pred_test = pred_test1;}
}

if (k > 0) {
// get class_current and profit from (k)th record
class_current = rs.getString("class_current");
test_profit = rs.getDouble("Profit_Loss");

[some calculations............]

pred_test = "";
class_current = "";
test_profit = 0;

pred_test1 = rs.getString("Class1_Predicted");

if (j == 0) { pred_test = pred_test1;}

}
 k++;
}
}
catch (SQLException e)
{
    myConsole.getOut().println(e);
} // end of simulation - 100 simulation records
-------------------------------------------------------
If you could indicate code changes to reverse the handling direction I would
be delighted

Thank you

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/Processing-a-subset-of-records-correctly-tp145844.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: Processing a subset of records correctly

Posted by Bob M <rg...@orcon.net.nz>.
Thank you John............

I shall try your suggestion

Functionality is more important than elegance for me :)

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/Processing-a-subset-of-records-correctly-tp145844p145848.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: Processing a subset of records correctly

Posted by John English <jo...@gmail.com>.
On 05/04/2016 08:45, Bob M wrote:
> I have just realized that I am processing the subset in reverse order (i.e.
> latest date backwards)
>
> I want to process in earliest date forwards direction
> rs = s.executeQuery("SELECT * FROM xxx WHERE TRADE_NO <>0 ORDER BY
> Trading_Date DESC,"
>          + " Trading_Time DESC FETCH NEXT 101 ROWS ONLY");

One way would be to wrap the first query inside another one: something 
like This:

   SELECT * FROM (SELECT * FROM xxx WHERE TRADE_NO <>0
                  ORDER BY Trading_Date DESC, Trading_Time DESC
                  FETCH NEXT 101 ROWS ONLY) AS x
            ORDER BY Trading_Date ASC

but I'm sure there must be a more elegant way to do it...
-- 
John English