Find a Portion of a Database in Ruby - ruby

Say for example I have the following database of instances of a class called Obj:
| id | attr1 |
+----+-------+
| 10 | A |
| 15 | B |
| 20 | C |
| 50 | D |
Now let's say I want to find all of the instances of Obj with id greater than 10. How would I do that?
I want to write Obj.where(id > 10).all. What is the proper way to accomplish this?
All help is appreciated. Thanks!

Have a try:
Obj.where("id > ?", 10)
you will find different ways to retrieve data from the database using Active Record from rails guide.

try
Obj.where("id > ?", 10)

Related

How can i merge multiple columns from two different files in talend

Lets say i have multiple columns coming from two different files like that :
USERNAME | AGE | GENDER | CHILDREN
Joe | 23 | male | 2
Annie | 45 | female | 5
| | |
And another one like this :
USERNAME | AGE |
Jonathan | 33 |
Mike | 41 |
And i want to merge the data of the columns that have the same name into one like this while keeping the data of the columns that are unique at each field:
USERNAME | AGE | GENDER | CHILDREN
Joe | 23 | male | 2
Annie | 45 | female | 5
Jonathan | 33 | |
Mike | 41 | |
Sorry if the answer is obvious, im new to talend, thanks.
What tool is available toy you?
The Append function in SAS for example can do this for you.
You can use the append approach in Python, R or other language you intend using.
For Talen:
Copy the complete subjob1 – copy me sub job and paste it to create a second sub job.
Link the two sub jobs using an onSubjobOK link.
Open tFixedFlowInput, and change Records from first subjob to Records from second subjob.
Open tFileOutputDelimited on the new sub job, and tick Append, as shown in the following screenshot:
use a tUnite component to accomplish that
here is the link of the documentation : https://help.talend.com/r/fr-FR/8.0/orchestration/tunite
your flow would be
tFileInput1(excel or csv ) ----------------------------------------------
|
| ->tUnite -> tLogRow
tFileInput2(excel or csv )->tMap (add to empty fields GENDER & Children )|

DAX to get latest date of an account name entry

I have found similar reported questions, but none of the solutions have worked so far. If I am entering the information incorrectly, please let me know.
I have a table in Power Pivot that contains repeated names, and dates entered that go with the names. What I am trying to do is get the latest date entered for a name.
Example:
Name | Date | Latest Date
A | 6/24/2016 |
A | 6/24/2017 |
A | 6/24/2018 |
B | 7/05/2010 |
B | 7/05/2011 |
C | 6/8/2009 |
C | 6/8/2010 |
C | 6/8/2011 |
What I would like under Latest Date is to have the latest date that corresponds to the Name. It should look like the following:
Name | Date | Latest Date
A | 6/24/2016 | 6/24/2018
A | 6/24/2017 | 6/24/2018
A | 6/24/2018 | 6/24/2018
B | 7/05/2010 | 7/5/2011
B | 7/05/2011 | 7/5/2011
C | 6/8/2009 | 6/8/2011
C | 6/8/2010 | 6/8/2011
C | 6/8/2011 | 6/8/2011
I've tried to use the following function, but all I keep getting are #Errors (of course changing the table reference based on the data in the file)
= CALCULATE(
MAX(Table1[Date]);
FILTER(Table1;
Table1[ID] = EARLIER(Table1[ID])
)
)
If the above function is correct, I wonder what I am doing wrong. Which one of the values in the () are column references and which ones are cell references? Perhaps that's where I am going wrong.
Any assistance is very appreciative. I tried to enter the information as nicely as possible so it can be assisted.
There are no cell or row references in DAX. Everything is done with filters.
Try this for Latest Date.
= CALCULATE(
MAX(Table1[Date]);
FILTER(ALL(Table1);
Table1[Name] = EARLIER(Table1[Name])
)
)
Give this a shot as well if that doesn't do the trick:
= CALCULATE(
MAX(Table1[Date]);
ALLEXCEPT(Table1; Table1[Name])
)

Laravel Eloquent GroupBy statement

I have this table and i'm trying to achieve a multiple groupBy and distinct through Laravel with a sum of duration. Basically, i need to find in table multiple ids passed from controller and then if windows, method and type are the same, sum the duration value.
Here is table structure
+-----+---------+--------+----------+------+
| ids | windows | method | duration | type |
+-----+---------+--------+----------+------+
| 1 | 2 | 3 | 5 | 2 |
+-----+---------+--------+----------+------+
| 2 | 2 | 3 | 5 | 2 |
+-----+---------+--------+----------+------+
| 3 | 2 | 3 | 5 | 2 |
+-----+---------+--------+----------+------+
and here is the statement that i try to use:
$tickets_g = \App\Models\Ticked::whereIn('id', $tickets)
->select('categoria', 'tipologia', 'priority', 'durata')
->distinct()
->GroupBy('categoria')
->GroupBy('tipologia')
->GroupBy('priority')
->sum('durata')
->get();
Can someone help me to figure out?
Fixed myself this is the correct query if someone stuck in the same issue:
$tickets_g = \App\Models\Ticked::select('support_ticked.*', DB::raw("SUM(support_ticked.durata) as durata_totale"))
->groupBy('support_ticked.tipologia','support_ticked.priority', 'support_ticked.categoria')
->get();

Re: Transpose data using Linq

I have a table, in the following format,
|BallotNo | City | CandidateNo | Votes
|Box1 | AA | Cand1 | 1200
|Box1 | AA | Cand2 | 1500
|Box2 | BB | Cand1 | 2500
|Box2 | BB | Cand2 | 3600
uing linq, I want to a get a result in the format
|Box1 |AA |Cand1 |1200 |Cand2 |1500
|Box2 |BB |Cand1 |2500 |Cand2 |3600
Thanks
You are looking for a grouping option.
As I have understood, you need to group by City row, it is pretty easy, see the http://msdn.microsoft.com/library/bb534492.aspx link on how to use the GroupBy extension method.

Select only the rows which timestamp correspond to the current month

I am starting to try some experiments using Google SpreadSheets as a DB and for that I am collecting data from different sources and inserting them via spreadsheets API into a sheet.
Each row has a value (Column B) and a timestamp (Column A).
+---------------------+------+
| ColA | ColB |
+---------------------+------+
| 13/10/2012 00:19:01 | 42 |
| 19/10/2012 00:29:01 | 100 |
| 21/10/2012 00:39:01 | 23 |
| 22/10/2012 00:29:01 | 1 |
| 23/10/2012 00:19:01 | 24 |
| 24/10/2012 00:19:01 | 4 |
| 31/10/2012 00:19:01 | 2 |
+---------------------+------+
What I am trying to do is to programmatically add the sum of all rows in Column B where Column A is equal to the current month into a different cell.
Is there any function that I can use for that? Or anyone can point me to the right direction on how can I create a custom function which might do something like this? I know how to do this using MySQL but I couldn't find anything for Google SpreadSheets
Thanks in advance for any tip in the right direction.
Would native spreadsheet functions do?
=ArrayFormula(SUMIF(TEXT(A:A;"MM/yyyy");TEXT(GoogleClock();"MM/yyyy");B:B))

Resources