I have a Parse class called Book. Inside it is a column pageNumber.
I want to query the most recent objects for each page number. There can be more than one object with the same pageNumber which is why I only want to query the most recent object for each value under pageNumber.
So, if there are six different objects with a value of (4) under pageNumber in the class Book how would I get just the most recently created object. Not just for pageNumber (4) but for all unique pageNumbers 1-50.
For a specific page number :
You should order the result by createdAt date, and set the limit of the query to 1 :
query.descending("createdAt");
query.limit(1);
For each page number, you can either iterate on every possible page number value, or retrieve everything and iterate other the results, selecting the most recent object for the same page number (using a hash table)
Related
I have a Dataverse table named my_sample_table.
Inside the table I have a column named my_sample_column of type integer whose max value should be returned. Am trying to achieve this by using the List rows action provided with PowerAutomate.
Is there a filter query that can be written on the Filter rows property ? similar to what we use with SQL : max(columnname)
Or any other queries that can be included in the List rows action which will return the same result.
I know that I can iterate through the column values to get the max value using an expresion or by sorting it and getting the topmost one. But I was wondering whether there are any direct approach to it.
I would try and use a max aggregate for this column in a Fetch Xml query:
https://learn.microsoft.com/en-us/power-apps/developer/data-platform/use-fetchxml-aggregation#max
I have an array with products, I need to display only 1 product, with the largest number in available_amount. How can i do this?
How do I iterate to display products with parameters:
- #part.wh_ps.sort_by(&:available_amount).each do |whp|
product number1: available_amount: 2;
product number2: available_amount: 5;
If those objects are mapped from the database being the result of a query and you already have them in memory, then you could use Enumerable#max_by:
#part.wh_ps.max_by(&:available_amount)
It should return the object within that array with the biggest available_amount if any.
If you need the one with the lowest available_amount, then Enumerable#min_by, and if you need both Enumerable#minmax_by.
However if that's not the case and you're hitting the database again, you could consider making the exact query using SQL (ActiveRecord) asking for the row with the biggest value for the given column.
I have two tables with some values .These two tables have one onetoone relations between them.In my first tables contains 70 values and Second table contains 20 values.I Created one fetch request for fetch values from 2nd table based on the condition.These condition is set by using predicate.I added the object return from the request execution in to one array.In some condition the Predicate will became fail in this situation what output will return by the fetch request.How i compare all array object with one class instance.
If nothing matches the predicate you will get an empty array back (which is logged as ()). If there is something wrong with the fetch / predicate then you will get an error (or exception).
You can use the containsObject: method on the array to check if a specific instance is in the list of returned objects.
So far I have a query with a result set (in a temp table) with several columns but I am only concerned with four. One is a customer ID(varchar), one is Date (smalldatetime), one is Amount(money) and the last is Type(char). I have multiple rows with the same custmer ID and want to evaluate them based on Date, Amount and Type. For example:
Customer ID Date Amount Type
A 1-1-10 200 blue
A 1-1-10 400 green
A 1-2-10 400 green
B 1-11-10 100 blue
B 1-11-10 100 red
For all occurrences of A I want to compare them to identify only one, first by earliest date, then by greatest Amount, then if still tied by comparing Types. I would then return one row for each customer.
I would provide some of the query but I am at home now after spending two days trying to get a correct result. It looks something like this:
(query to populate #tempTable)
GROUP BY customer_id
HAVING date_cd =
(SELECT MIN(date_cd)
FROM order_table ot
WHERE ot.customerID = #tempTable.customerID
)
OR date_cd IS NULL
I assume the HAVING would result in only one row per customer_id. This did not end up being the case since there were some ties there.
I am not sure I can do the OR - there are some with NULL values here - and it did not account for the step to the next comparison if they were all the same anyway. I am not seeing a way to avoid doing some row processing of the temp table with some kind of IF or WHERE loop.
As I write I am thinking maybe I use #tempTable.date_cd in the HAVING clause instead of looking at the original table. but that should return the same dates?
Am I on the right track or is there something missing? Suggestions? More info??
try below query :-
select * from #tempTable
GROUP BY customer_id
HAVING isnull(date_cd,"1900/01/01") =min(isnull(date_cd,"1900/01/01"))
I'm tracking if a user has liked and or voted on a object in a list of objects others posted.. I can get either likes and votes, but not both. (A person can both like and vote on an object and these options are not mutually exclusive).
To simply this problem let me describe it in relational terms (left joins used - object is ALWAYS returned, liker and voter data is only returned if a record of that type exists)
[object]+ -> liker
+ -> voter
What I'd like to return is:
objectID likerID voterID
2343 null 88
2345 11 null
2382 44 1256
2400 null null
Yet every which way I've sliced I cannot get it to come out like that . Either row 2400 is skipped (I've tried every combination of where), or values are even shifted from likerID to the voterID column (bug?).
Here is a sample of the cypher:
start objects=node(158)
match contestant-[:POSTED]->object_node-[:POSTED_OBJECT]->objects<-[?:POSTED_OBJECT]-object_node_a<-[?:LIKES]-liker
, objects<-[?:POSTED_OBJECT]-object_node_b<-[?:VOTES]-voter
return id(object, id(liker), id(voter)
It doesn't work even if I try where id(object_node_a) = id(object_node_b)...
If I just try to get a liker it works.. same with voter.. but when I try to do both.. bombs..
I've tried using where , etc but ultimately I never get the full list of objects - it either trims down the list based upon matches, or gives me the Cartesian product which distinct does not resolve.
SQL EXAMPLE: LEFT JOIN
I'm a sql guy so let me explain it this way - I have a objects table on the left, and I want to left join it to a liker table and a voter table, and return both the liker id and voter id on a single row along with the object data. All the object records will be returned regardless if there is a voter or liker record.
[object]+ -> liker
+ -> voter
IS THIS EVEN POSSIBLE?
Is it possible to do this via cypher?
Hopefully I haven't misunderstood. To get
objectID likerID voterID
2343 null 88
2345 11 null
2382 44 1256
2400 null null
i.e. all objects and the ID of those that liked it and voted for it, this query should do it-
start o=<lookup for objects>
match ul-[like?:LIKED]->o, uv-[vote?:VOTED]->o
return o,ID(ul),ID(uv)
This will return objects that no votes and likes, both votes and likes and either one. Note that if you have multiple users voting for the same object as is likely, then your object row will repeat for each user. You might want to do something like
start o=<lookup for objects>
match ul-[like?:LIKED]->o, uv-[vote?:VOTED]->o
return o,collect(ID(ul)),collect(ID(uv))
to still get a row per object but a collection of user IDS for votes and likes.
To include the person that posted the object as well:
start o=node(4,5,6,7)
match ul-[like?:LIKED]->o, uv-[vote?:VOTED]->o, c-[:POSTED_OBJECT]->o
return o,ID(ul),ID(uv),ID(c)
I created a tiny sample to play with: http://console.neo4j.org/r/in8g4w