How to replicate/clone all data in a table that has self-relation in Laravel?
I have this table:
members table
id
member_id
company_id
name
1
null
23
John
2
1
23
James
3
1
23
Ken
4
null
23
Test
5
3
23
Max
EXISTING CODE
And I want to replicate all data that has company_id of 23 using
$members = Members::where['company_id' => 23]->get();
foreach ($members as $member) {
$duplicate = $member->replicate()->fill(['company_id' => 24);
$duplicate->save();
}
Results of the code
members table
id
member_id
company_id
name
1
null
23
John
2
1
23
James
3
1
23
Ken
4
null
23
Test
5
3
23
Max
6
null
24
John
7
1
24
James
8
1
24
Ken
9
null
24
Test
10
3
24
Max
But in that code, the replication of self-relation is wrong. How can I do it?
Expected result
members table
id
member_id
company_id
name
1
null
23
John
2
1
23
James
3
1
23
Ken
4
null
23
Test
5
3
23
Max
6
null
24
John
7
6
24
James
8
6
24
Ken
9
null
24
Test
10
8
24
Max
I'm sorry if my English is messed up, but I hope you get the idea of what I'm trying to do. Thank you!
Try this .You have two options to replicate
$members = Members::where(['company_id' => 23])->get();
foreach ($members as $member) {
$duplicate = $member->replicate();
$duplicate->company_id=24;
$duplicate->save();
}
});
or
$members = Members::where(['company_id' => 23])->get();
foreach ($members as $member) {
$duplicate = $member->replicate()->fill(['company_id'=>24]);
$duplicate->save();
}
});
Updated
$members = Members::where(['company_id' => 23])->get();
$tempIdMap=[];
foreach ($members as $key=>$member) {
if($key==0){
$tempIdMap[$member->id]=$member->member_id;
}
$duplicate = $member->replicate()->fill(['company_id'=>24,'member_id'=>isset( $tempIdMap[$member->member_id])? $tempIdMap[$member->member_id]:null]);
$duplicate->save();
$tempIdMap[$member->id]=$duplicate->id;
}
oracle version: 11.2.0.1.0
When I try to generate an AWR Report in Oracle use sysdba,
exec dbms_workload_repository.create_snapshot();
I keep getting this error:
ORA-00600: [kewrose_1], [600], [ORA-00600: [13013], [5001], [6213], [8465936], [5], [8447794], [17], [], [], [], [], []
], [], [], [], [], [], [], [], [], []
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this
conn / as sysdba
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
Current Instance
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
3400239050 TEP 1 TEP
Specify the Report Type
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type: dec
Type Specified: dec
Instances in this Workload Repository schema
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 3400239050 1 TEPCBC TEP oldman
Using 3400239050 for database Id
Using 1 for instance number
Specify the number of days of snapshots to choose from
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Enter value for num_days: 1
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
TEP TEP 38542 20 Dec 2022 00:30 1
38543 20 Dec 2022 01:30 1
38544 20 Dec 2022 02:30 1
38545 20 Dec 2022 03:30 1
38546 20 Dec 2022 04:30 1
38547 20 Dec 2022 05:30 1
38548 20 Dec 2022 06:30 1
38549 20 Dec 2022 07:30 1
38550 20 Dec 2022 08:30 1
38551 20 Dec 2022 09:30 1
38552 20 Dec 2022 10:30 1
38553 20 Dec 2022 11:30 1
38554 20 Dec 2022 12:30 1
38555 20 Dec 2022 13:30 1
38556 20 Dec 2022 14:30 1
38557 20 Dec 2022 15:30 1
38558 20 Dec 2022 16:30 1
38559 20 Dec 2022 17:30 1
38560 20 Dec 2022 18:30 1
38561 20 Dec 2022 19:30 1
38562 20 Dec 2022 20:30 1
Specify the Begin and End Snapshot Ids
Enter value for begin_snap: 38542
Begin Snapshot Id specified: 38542
Enter value for end_snap: 38544
End Snapshot Id specified: 38544
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_38542_38544.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: test2
Using the report name test2
<html lang="en"><head><title>AWR Report for DB: TEP, Inst: TEP, Snaps: 38542-38544</title>
<style type="text/css">
body.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black; background:White;}
I would like to add on to this code so that the value of the last measurement according to the "date" column in the "measurement" column is divided by the lowest value recorded in the measurement column and the result forms a new column. The current working code adds a column that subtracts the initial measurements from the other measurements in the "measurement" column if the "subject", "type" and "procedure" columns match. Thank you in advance.
data have;
input Subject Type Date $ 5-12 Procedure $ 15-22 Measurement;
datalines;
500 Initial 15 AUG 2017 Invasive 20
500 Initial 18 SEPT 2018 Surface 35
500 Followup 12 SEPT 2018 Invasive 54
428 Followup 2 JUL 2019 Outer 29
765 Seventh 3 JUL 2018 Other 13
500 Followup 6 NOV 2018 Surface 98
428 Initial 23 FEB 2018 Outer 10
765 Initial 20 AUG 2019 Other 19
610 Third 21 AUG 2018 Invasive 66
610 Initial 27 Mar 2018 Invasive 17
;
data want (drop=rc _Measurement);
if _N_ = 1 then do;
declare hash h (dataset : "have (rename=(Measurement=_Measurement) where=(Type='Initial'))");
h.definekey ('Subject');
h.definedata ('_Measurement');
h.definedone();
end;
set have;
_Measurement=.;
if Type ne 'Initial' then rc = h.find();
NewMeasurement = ifn(Measurement=., ., sum (Measurement, -_Measurement));
run;
Seeking help with the following problem statement.
I/P Data Set:
customer id invoice date item id invoice amount Comment
1 10-Jan-2014 1 10 Start of 12 month window - 10th Jan 2014 to 10th Jan 2015
1 20-Jan-2014 2 20 Falls within 12 month window
1 21-Aug-2014 1 10 Falls within 12 month window
1 31-Dec-2014 1 10 Falls within 12 month window
1 20-Feb-2015 1 10 Start of new 12 month window as this is post 10th Jan 2015
1 30-Mar-2016 1 10 Start of new 12 month window as this is post 20th Feb 2016
Desired o/p
customer id invoice date item id invoice amount window sum(amount where item id = 1)
1 10-Jan-2014 1 10 1 10
1 20-Jan-2014 2 20 1 0
1 21-Aug-2014 1 10 1 20
1 31-Dec-2014 1 10 1 30
1 20-Feb-2015 1 10 2 10
1 30-Mar-2016 1 10 3 10
I tried using the following query in Hive to achieve the above output but the challenge is in resetting the next window once we have crossed the 12 month mark. (Please refer to rows 5 and 6 in the input data set). The need is for these records to be considered as start of a new window.
Following Query Used:
SELECT SUM(if(item_id = 1, invoice_amount, 0)) OVER (
PARTITION BY customer_id
ORDER BY invoice_date ASC
RANGE BETWEEN 31556926 PRECEDING AND CURRENT ROW
) FROM INVOICE_DETAILS;`
I have an existing excel template as like below :
DATE 7/28/2016 7/29/2016 July MTD YTD
Call Activity
IB_Calls_Offered 22 29 52 52 52
IB_Calls_Answered 22 29 52 52 52
Sale 6 3 9 9 9
Everyday when my SP get executed , I need to add a extra column (as Current Date) and fill the corresponding data.
Kindly Suggest me how to do it by using SSIS/SSRS