I currently have two datasets, RTWANEW2016.sav and MERGED.sav.
RTWANEW2016:
+----+------------+--------+--------+--------+--------+--------+--------+
| id | date | value1 | value2 | value3 | value4 | value5 | value6 |
+----+------------+--------+--------+--------+--------+--------+--------+
| 1 | 01-03-2006 | 3 | 9 | 85 | 766 | 3 | 45 |
| 1 | 03-23-2010 | 56 | 34 | 23 | 33 | 556 | 43 |
| 2 | 12-04-2014 | 56 | 655 | 523 | 566 | 9 | 9 |
| 3 | 07-23-2011 | 34 | 56 | 661 | 23 | 22 | 11 |
| 4 | 03-05-2007 | 45 | 345 | 222 | 556 | 4566 | 4 |
+----+------------+--------+--------+--------+--------+--------+--------+
MERGED:
+----+------------+--------+--------+--------+
| id | date | value4 | value5 | value6 |
+----+------------+--------+--------+--------+
| 1 | 01-03-2006 | 345 | 44 | 5345 |
| 2 | 12-04-2014 | 522 | 55 | 5444 |
| 4 | 03-05-2007 | 234 | 88 | 9001 |
+----+------------+--------+--------+--------+
I want to update RTWANEW2016 with the values from variables "value4", "value5" and "value6" from MERGED.
Notice that some data RTWANEW2016 has duplicate ID's, but different dates, so I would need to sort by both id and date
See the UPDATE command which is designed to achieve this.
Overview (UPDATE command)
UPDATE replaces values in a master file with updated values recorded
in one or more files called transaction files. Cases in the master
file and transaction file are matched according to a key variable.
The master file and the transaction files must be IBM® SPSS®
Statistics data files or datasets available in the current session,
including the active dataset. UPDATE replaces values and creates a new
active dataset, which replaces the original active dataset.
UPDATE is designed to update values of existing variables for existing
cases. Use MATCH FILES to add new variables to a data file and ADD
FILES to add new cases.
UPDATE FILE='/RTWANEW2016.sav'
/FILE='/MERGED.sav'
/BY=ID Date.
Related
I record eftpos payments that are payed as a group at the end of each day, but am having trouble matching individual payments to the daily total
Payments table:
|id | paymentjobno| paymentamount| paymentdate|paymenttype|
| 1 | 1000 | 10 | 01/01/2000 | 2 |
| 2 | 1001 | 15 | 01/01/2000 | 2 |
| 3 | 1002 | 18 | 01/01/2000 | 2 |
| 4 | 1003 | 10 | 01/01/2000 | 1 |
| 5 | 1004 | 127 | 02/01/2000 | 2 |
I want to return something like this so I can match it to $43 transactions on the following day and record payment ID numbers against the transaction
|id | paymentjobno| paymentamount| paymentdate|paymenttype|daytotal|
| 1 | 1000 | 10 | 01/01/2000 | 2 | 43 |
| 2 | 1001 | 15 | 01/01/2000 | 2 | 43 |
| 3 | 1002 | 18 | 01/01/2000 | 2 | 43 |
Below is my current attempt, but I only get one returned row per day even if there's multiple payments, and the daytotal is the same for every returned result, which is also not the value I was expecting. What am I doing wrong?
SELECT
id,
paymentjobno,
paymentamount,
paymentdate,
paymenttype,
t.daytotal
FROM payments
LEFT JOIN (
SELECT SUM(paymentamount) AS daytotal
FROM payments
GROUP BY paymentdate) t ON id = payments.id
WHERE paymenttype = 2 AND paymentdate $dateclause
GROUP BY payments.paymentdate
I tried to search and experimented, but couldn't figure out, how to add slim to rails stats views statistics. It is counting only .erb templates, but I want .slim to be added as these are views too.
% bin/rails stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers | 3245 | 1634 | 57 | 218 | 3 | 5 |
| Helpers | 186 | 149 | 0 | 18 | 0 | 6 |
| Jobs | 34 | 20 | 2 | 2 | 1 | 8 |
| Models | 879 | 541 | 25 | 77 | 3 | 5 |
| Mailers | 85 | 53 | 3 | 6 | 2 | 6 |
| Channels | 46 | 28 | 3 | 4 | 1 | 5 |
| Views | 0 | 0 | 0 | 0 | 0 | 0 |
+----------------------+--------+--------+---------+---------+-----+-------+
I could add an extra rules for something like "Slim views", but this would count the .erb templates in views too.
I am using psql and joined three tables A, B and C from table A.
For example resulting table is as follows:
+----+------+------+------+
| pk | a_id | b_id | c_id |
+----+------+------+------+
| 1 | 5 | 12 | 16 |
| 2 | 5 | 7 | 8 |
| 3 | 5 | 6 | 21 |
| 4 | 8 | 12 | 16 |
| 5 | 8 | 3 | 9 |
| 6 | 9 | 11 | 32 |
| 7 | 9 | 8 | 2 |
+----+------+------+------+
I am trying to create c_id relations over a_id. In a_id there are three groups [5,8,9]. For example c_id=16 has a relation to a_id=[5,8], so c_id=[8,21,9,32] must be protected via a_id=[5,8]. And resulting table should look like as follows:
+----+------+------+------+
| pk | a_id | b_id | c_id |
+----+------+------+------+
| 1 | 5 | 12 | 16 |
| 2 | 5 | 7 | 8 |
| 3 | 5 | 6 | 21 |
| 4 | 8 | 12 | 16 |
| 5 | 8 | 3 | 9 |
+----+------+------+------+
How can I write such a condition in join statement?
After the join, you can write this query. I created your result table directly, and then I wrote a SQL query.
SELECT * from res
WHERE a_id in (SELECT distinct a_id
FROM res
WHERE c_id=16)
I have a SPSS dataset with information of different household members and I need to generate a new variable that counts the number of people that compose each one of these households.The original dataset is something like:
ID | age | height
332 | 23 | 1.78
332 | 27 | 1.65
344 | 56 | 1.79
344 | 34 | 1.98
344 | 15 | 1.58
etc... and I need to generate a new variable that counts the id repetitions such as 'n' in:
ID | age | height | n
332 | 23 | 1.78 | 2
332 | 27 | 1.65 | 2
344 | 56 | 1.79 | 3
344 | 34 | 1.98 | 3
344 | 15 | 1.58 | 3
Is there any straightforward way to do it with window commands or do I need to use command language?
Look up the AGGREGATE command.
AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK=ID /Count=N.
I have this cucumber task:
Then I should see following posting modes
| row | day | hour | minute | location | category |
| 1 | 1 | 7 | 0 | 29 | 6 |
| 2 | 2 | 8 | 5 | 27 | 7 |
| 3 | 3 | 9 | 10 | 28 | 18 |
| 4 | 4 | 15 | 15 | 29 | 18 |
| 5 | 5 | 17 | 20 | 27 | 7 |
| 6 | 6 | 20 | 30 | 28 | 6 |
| 6 | 0 | 22 | 50 | 29 | 7 |
And behind it there is this description:
Then /^I should see following posting modes$/ do |table|
table.hashes.each do |posting|
within("#itemPosting .attributeContainer table tbody tr:eq(#{posting[:row]})") do
find("#item_posting_day").value.should == posting[:day]
find("#item_posting_hour").value.should == posting[:hour]
find("#item_posting_minute").value.should == posting[:minute]
find("#item_posting_location").value.should == posting[:location]
find("#item_posting_category").value.should == posting[:category]
end
end
end
So this part:
tr:eq(#{posting[:row]})
doesn't work(it goes to next step, and then gives an error that #item_posting_day is not found.)
But if I do this instead:
tr:eq(4)
It works (finds the #item_posting_day field, gets its value, and then gives an error saying that value is not what is expected to be, but that's ok).
So I don't understand what's the problem with using this syntax:
tr:eq(#{posting[:row]})
It seems that hashes converts column headers to strings, not symbols. Try to use 'row' instead of :row