I have 10000 records in database i want to fetch 100 record first time next 100 record 2nd time and so on. I'm using setFirstResult() and maxResult(). I'm maintaining a counter to update set first result offset setFirstResult(count) is always started from first index whatever value you put inside it, it start from 0.
List<StudentBo> bos=manager.createNamedQuery("getAllApplicantForRegistration")
.setParameter("batch",dto.getBatch())
.setFirstResult(count)
.setMaxResult(lastIndex).getResultList();
setFirstResult will incease every time while setMaxResult will be static.
Related
Consider there are 30000 events in a contract.
getPastEvents() method returns max 10000 results and if something goes above 10000 it throws error. Is there any recursive option where we can loop and track the 10000 results. When it comes to 10000 it restarts from that last block number and fetch another 10000.
First loop 10k, second loop 10K, and third loop 10k without any error summing up 30k.
I know this is a tough one but I'm basically trying to say. Give me a service call and its completion date, then give me the Max date for all service calls where the date is less than the date of the service call I'm inquiring about.
Basically the end result I'm looking for is to say was there another service call on this piece of equipment that was within the last 30 days.
So as you can see in the image for say Asset 50698 service call 579032 we have a date of 11/9/2020 the call below that was 10/22/2020 which was less than 30 days. I want to somehow find a way to count how many service calls I have where this has occurred. Is this possible?
I think you're looking for a context operator In, ForEach or ForAll (in in this case)
Add a variable "MaxAssetDate" and assign it a Formula similar to the following based on your column headers.
=Max([Service Call Completion Date] In ([Asset ID];[Service Call])) In (Asset ID])
Then add this as a column. Provided you have a prompt filtering for a given asset or "date" this column will then show the max date for each service call of the same asset ID. Then add a new variable: ServiceCallDaysDiff: Then by using DatesBetween() with "MaxAssetDate" and ServiceCallCompletionDate and DayPeriod; =DatesBetween([ServiceCallCompletionDate];[MaxAssetDate];DayPeriod) you should get a number 0-X. Then add a filter based if the number is between 1 and 30 then you show those records, otherwise hide the rest; or do whatever logic is then needed.
Now if you're dealing with hundreds of thousands of records this isn't ideal as you're putting all the processing on the webi engine when it ideally would occur as an object in the database layer. However if you only have a few thousand records this should be managable.
To add a count of service calls...
add variable: ServiceCallsCount:
=Sum(Sum(If([ServiceCallDaysDiff]=0;0;1)) In ([AssetID]))
this will count the non zero day differents. Note this will extend beyond 30 so if you want to limit by 30 days adjust the if statement to zero out those not between 1 and 30.
This is but one approach: there may be simpler ways.
I'm working on a project using Automation Anywhere Client.
I'm extracting data from MS Excel to MS Access using SELECT and UPDATE statements, but it is possible that the data could repeat itself, and in this case, I would like to UPDATE only 3 fields, those are the statements that I'm using
INSERT INTO $vDiagnosis$
VALUES ('$vID$','$vFirstName$','$vLastName$','$vGender$','$vPhone$','$vAge$',
'$vDateOfVisit$','$vCondition$','$vInsuranceCo$','$vInsuranceNr$','$vVisitingNumber$')
Update $vDiagnosis$
SET DateOfVisit = '$vDateOfVisit$', Condition = '$vCondition$'
WHERE ID = '$vID$'
which are the DateOfVisit and the Condition and the VisitingNumber (which is the number of times someone visited that hospital). The thing is, I'm trying to increment the VisitingNumber every time the UPDATE statement is executed, for example, someone visits today, I want it to be 1, the UPDATE statement is executed again, I want that 1 to increment.
I tried making a variable, and to increment it every time the UPDATE is being executed but whenever it loops and goes to the next INSERT statement, it continues incrementing, even if it inserts a new value.
A preview of the work I'm trying to do on Automation Anywhere
Any help would be appreciated.
Thanks in advance!
Not sure about the variable aspect mentioned, but bumping the VisitingNumber count should be able to be done as:
UPDATE $vDiagnosis$
SET DateOfVisit = '$vDateOfVisit$',
Condition = '$vCondition$',
VisitingNumber = VisitingNumber + 1
WHERE ID = '$vID$'
To the insert, the value for the visitingNumber could simply be 1 without a variable, like so:
INSERT INTO $vDiagnosis$
VALUES ('$vID$','$vFirstName$','$vLastName$','$vGender$','$vPhone$','$vAge$',
'$vDateOfVisit$','$vCondition$','$vInsuranceCo$','$vInsuranceNr$', 1)
Or better, perhaps a default value of 1 could be specified at the table level, and then it would not need to be included with the insert query at all. (it would be set to 1 at insert)
Hope that makes sense.
I have a database table, for example 'items'. I have a timeline of these items, sorted by field ascended_at (datetime). I need to make a pagination api for such timeline. So, the first my version was:
HTTP GET /items/timeline?page=[PAGE_NUM]
which fires
SELECT * FROM items LIMIT 10 OFFSET [0, 10, 20, ...] ORDER BY ascended_at;
but here is the problem: when new item arrives, all pages shifts per 1 item. To avoid this, i have added from_asc_at parameter:
HTTP GET /items/timeline?page=[PAGE_NUM]&from_asc_at=123123123
which fires
SELECT * FROM items WHERE ascended_at <= [asc_at_parameter] LIMIT 10 OFFSET [0, 10, 20, ...] ORDER BY ascended_at;
but this is not accurate, because it is possible to have two items with same ascended_at, and you can see the same item in two different pages (but should not).
So, my question is: what are the possible solutions for this?
Use ID (because it is unique)? But what if it is not ordered by ID?
Any ideas more?
If your items IDs are auto-incremented, you could check what will be the next "autoincrement" value when retrieving items the first time (before pagination).
Store that value persistently (maybe in a session var) until the next search, and add a filter < {maximumID} to your SQL query, to improve the "result set stability" when the user paginates (all new items created between the initial search and paginations won't be retrieved).
EDIT
To handle items deletions, you will have to do "soft deletes" : do not immediately delete an item from DB, but store a deletion date in a datetime field, so that items still exist in DB for a while.
When a new search is issued, you will store in session the current server time, and add a criteria (for example date_deleted IS NULL OR date_deleted > {searchDate}), so that all the items deleted after a search will still be displayed for that specific search.
You will have to create a scheduled job to "really" delete items from DB after some delay.
I am taking over designing a CMS from another programmer. As the site is filling up, we're finding loops in mysql queries causing long hangs. I have found a temp solution for this one, but am wondering if there is a quicker way of doing it?
take the table (tracks resources):
id resource click
1 res_1 192
2 res_2 12
3 res_3 300
what we need to get is a popularity of the resource - res_click/total_click
what he had was a while loop:
while ($item = mysql_fetch_array ($result)) $total_clicks = $total_clicks + $item[0];
As there could be 100 or more resources to a page, this was running for each resource, and it is causing major hangs.
My solution is to get a sum:
SELECT SUM(click) FROM uri
SELECT click FROM resource WHERE id=$x
then divide them both.
But this two calls are still running for around a 100 items per page. Is there a way I can have a field in mysql that is the result of a formula based on another another, like in excell? So I could add a field "percentage", tell mysql that it is the sum of click divided by the current click value, then every time click is updated the 'percentage' field is automatically updated?
any help would be appreciated,
cheers ;)
you can create a view on your table that present the sum you want