Using pluck with maximum - ruby

Is it possible to chain options when using maximum?
I have a PhoneStats class and I want to pull the name from a few columns who have the maximum value in the table. For example if I run
PhoneStat.maximum('calls')
I get the value I expect but I would like to get maximum value as well as the id of the user in that record. Is it possible to use pluck or collect for something like this?
Thanks spickermann
Thanks. Below got me exactly what I needed.
PhoneStat.order('calls DESC').pluck(:name).first

You have to write this a bit more detailed:
PhoneStat.order('calls DESC').first

Related

An error when trying to aggregate using data.table

table users,
I have the code as shown in the screenshot and the resulting error. Unfortunately I can't share the data due to privacy issues. Does anyone have an idea of the error?
Thanks in advance!
When you use by, the resulting data.table should have one row per group. However, you try to assign multiple values to each of these lines by using unique() (given there are multiple unique values per group). You either have to wrap them in list() or paste(..., collapse = ", ") or something like that to just get a single value in each by.

Elquent Relation Limit records

I'm trying to send API with certain number of records
$category->products
I tried to use limit() or take() but it fails
so is there any smart solution than go to pivot and select it with limit ??
Copy data to a new collection.
$collection =$category->products;
you can now send the number of times you want using take ().
for example;
$collection->take(5);
if your question is different please explain it more clearly.
I found the solution I was easy
$category->products()->limit(2)->get()->all()
that's all

is there anyway i can pass an array to getAll()?

I am looking for a good way to do the following.
Get a list of uids from tableA like..
r.Table('tableA').get(1)('somelistofuid')
Then I want to use the list go get all the data I need from tableB
r.Table('tableB').getAll(listfromQueryAbove)
I know that i can do getAll(a,b,c) to get a,b,c but could there be a simpler way?
You want something to unpack an array into an argument list, that's args.
So change your query to
r.Table('tableB').getAll(r.args(listfromQueryAbove))
and it should work.
You can use r.args for this:
r.table('table').getAll(r.args(ARRAY))

Distinct count a field that has been sorted by territory from another source

I am trying to find a way to get a distinct count on a field that is being filtered by a territory without using grouping because of the fact that I need to then pass this value over to another report. The easiest way would be something like this:
distinctcount({Comm_Link.CmLi_Comm_CompanyId}) if {Company.Comp_Territory}='Atlanta'
But for obvious reasons that won't work. Any thoughts?
what you have to do is a running total. Right click on {Comm_Link.CmLi_Comm_CompanyId} insert running total, type of summary will be distinct count and on evaluate where says Use a formula type your condition {Company.Comp_Territory}="Atlanta"
your formula and approach is wrong.. I doubt whether your formula compiled with out any errors...
first create the value and then find the distinct count
if {Company.Comp_Territory}='Atlanta'
Then {Comm_Link.CmLi_Comm_CompanyId}
Now in footer write or you can get it by right click on the filed.
distinctcount({Comm_Link.CmLi_Comm_CompanyId})

Get maximum value with Zend_Db_Table

Ive got a Zend_Db_Table
Now I want to get the maximum available value of a field.
Is there a way to get the MAX(number) value or do I need to use basic SQL?
Thanks!
Use
new Zend_Db_Expr('MAX(number)')
as one of the fields in the Zend_Db_Table_Select.

Resources