How to populate data in one table from another table in MySQL - mysql

i have two tables in my toll database in MySQL, namely traffic_shift_wise and traffic_day_wise. And the columns of these tables are as follows:
Table traffic_shift_wise
toll_id date shift car_single car_return car_total
1 2016-09-01 1 25 10 35
1 2016-09-01 2 50 25 75
1 2016-09-02 1 100 50 150
1 2016-09-02 2 200 100 300
traffic_day_wise
toll_id date car_single car_return car_total
1 2016-09-01 75 35 110
1 2016-09-02 300 150 450
There are two shifts in day for a specific toll, here you can see that i have to take data from the traffic_shift_wise to traffic_day_wise, automatically just after insert in traffic_shift_wise.
So, please help me out with this. What should i use, triggers.. ?

Related

Minimum difference of the values in column Y where the column X value must be different from each other

I want to know the minimum difference of 2 values in building_num where the worker_num must be different from each other. For example check this table:
worker_num | building_num
39 0
39 2
39 6
39 7
39 15
39 21
39 25
39 27
39 29
39 30
39 31
50 0
50 1
50 3
50 15
50 16
50 18
50 19
50 24
50 25
50 32
So The 2 closest compared numbers are 0(39) & 0(50) and 15(39) & 15(50) and 25(39) & 25(50). They are all the same values so the difference is 0. So it must output 0.
If these rows weren't in it, the closest numbers could be 2(39) & 1(50), which have a difference of 1. So then the output must be 1.
The SQL code must be so simple, but I couldn't find a source. Any help is appreciated.
SELECT MIN(t1.building_num - t2.building_num)
FROM table t1
JOIN table t2 ON t1.worker_num != t2.worker_num
AND t1.building_num >= t2.building_num

MySQL trigger update other rows on same table

I'm trying to update the same table after an insert's trigger.
I know that you can't update the same table on a trigger but I can't seem to find an alternative.
I have for example the following table :
id | team | time
1 A 1 568 725 200
2 A 1 568 725 200
3 B 1 568 824 950
If I update id 1 time from 1 568 725 200 to 1 568 455 800, id 2 time's should also be updated to 1 568 455 800
because they are in the same team (A).
Is there a solution to achieve this update inside the trigger's transaction?
I'm working on a bad designed database and I can't change much.

MS Access calculation i cant figure out

I need to create a table in MS Access like the following.
It's plain and simple, but I just cant figure it out.
For example
ID debit credit balance
1 50 50
2 20 70
3 30 40
4 15 55
5 30 85
Thanks

Do a Page Break on the same page of SSRS Report

I want to show 50 rows in one page of the SSRS Report. But I want to show these 50 rows in two columns of 25 rows each. Is there a way to do a page break on the same page or is there any other way to achieve this?
Depending on how you want to arrange your data, you will need to have two separate tables each configured to only show 25 rows sorted so that it displayes as you require (Read across then down or down one table then the other?)
One way to do this would be to create a hidden row group as #MiguelH suggested in their comment that has two levels to it, so you group into 50s and 25s along the lines of:
Row # - Group 1 - Group 2
1 1 1
2 1 1
....
24 1 1
25 1 1
26 1 2
27 1 2
....
49 1 2
50 1 2
51 2 1
52 2 1
....
74 2 1
75 2 1
76 2 2
77 2 2
....
98 2 2
99 2 2
100 3 1
101 3 1
You can then set a page break after your table group, displaying all records with a Group 2 value of 1 in the first table and a Group 2 value of 2 in your second table on the same page.

Maintaining the history of values in table/ track the changes of table by date

Following is my table structure:
PROJECT_ID MODULE_ID PASS FAIL RETEST NOT_EXECUTED TOTAL
TEST_1 TEST_1_MOD_1 10 5 2 2 19
TEST_1 TEST_1_MOD_2 20 5 5 0 30
TEST_1 TEST_1_MOD_3 30 5 2 0 37
TEST_1 TEST_1_MOD_4 40 5 7 2 54
TEST_1 TEST_1_MOD_5 50 5 2 0 57
And every day I will update the numbers in Pass, fail, retest, net executed and total column of this table. I am doing this using a webpage (as front end for both viewing and updating the table).
Now the problem arises when I want to see the status as of 2 days before. To be more clear, data as of Mar-09 will look like:
PROJECT_ID MODULE_ID PASS FAIL RETEST NOT_EXECUTED TOTAL
TEST_1 TEST_1_MOD_1 10 5 2 2 19
TEST_1 TEST_1_MOD_2 20 5 5 0 30
TEST_1 TEST_1_MOD_3 30 5 2 0 37
TEST_1 TEST_1_MOD_4 40 5 7 2 54
TEST_1 TEST_1_MOD_5 50 5 2 0 57
And on Mar-10 I updated the values in table as
PROJECT_ID MODULE_ID PASS FAIL RETEST NOT_EXECUTED TOTAL
TEST_1 TEST_1_MOD_1 20 5 2 2 29
TEST_1 TEST_1_MOD_2 20 5 5 5 35
TEST_1 TEST_1_MOD_3 30 5 12 0 47
TEST_1 TEST_1_MOD_4 40 5 7 2 54
TEST_1 TEST_1_MOD_5 60 5 2 0 67
and on Mar-11 I want to see the status as of Mar-09 which is:
PROJECT_ID MODULE_ID PASS FAIL RETEST NOT_EXECUTED TOTAL
TEST_1 TEST_1_MOD_1 10 5 2 2 19
TEST_1 TEST_1_MOD_2 20 5 5 0 30
TEST_1 TEST_1_MOD_3 30 5 2 0 37
TEST_1 TEST_1_MOD_4 40 5 7 2 54
TEST_1 TEST_1_MOD_5 50 5 2 0 57
I have a non-feasible solution which is to add a new column in the table called 'DATE_UPDATED' and I should insert new rows for each module everyday. But I'm afraid this will increase the table space.
Is this the best practice? or do we have any other better solution? Please help!
Any help would be greatly appreciated!