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
Related
I am trying to write a MySQL select statement which will use table1 and table2 to generate a table3.
table1
id
Month
Year
Name
Length
Breath
1
January
2002
Square
5
2
2
February
2003
Circle
6
3
3
March
2004
Cylinder
7
4
4
April
2005
Cube
8
5
5
May
2006
Quadilateral
9
6
table2
id
Month
Year
Name
Frequency
Area
Volume
1
January
2002
Square
1
20
50
2
Febrauy
2003
Circle
2
25
55
3
March
2004
Cylinder
3
Null
60
4
April
2005
Cube
4
35
65
5
May
2006
Quadilateral
5
40
Null
table3 the generated table should be like this.
Name
Type
Month
Year
Length
Breath
Frequency
Volume/Area
Cum_Area
Cum_Volume
Area
Volume
Square
2d
January
2002
5
2
1
2.5
20
50
20
50
Circle
2d
February
2003
6
3
2
2.2
45
105
25
55
Cylinder
3d
March
2004
7
4
3
2
45
165
30
60
Cube
3d
April
2005
8
5
4
1.86
80
230
35
65
Quadilateral
4d
May
2006
9
6
5
1.75
120
230
40
70
In the statements I've tried whenever the cumulative column encounters the first null value, every row from then on is null.
Also, how do I write the type column? I'd like square and circle to be '2d'; cube and cylinder to be '3d' and Quadrilateral to be '4d'.
Table 1 and 2 have the Name, Month and Year column in common.
I don't finish to understand what is your logic or why you don't have ids on the second table. But assuming what you write, this is a SUGGESTION.
Update your question I'll glad to update my answer.
Assuming null means 0:
SELECT
table1.Name,
CASE table1.Name
WHEN Square THEN '2d'
WHEN Circle THEN '2d'
WHEN Cylinder THEN '3d'
WHEN Cube THEN '3d'
WHEN Quadilateral THEN '4d'
END as Type,
table1.Month,
table1.Year,
table1.Length,
table1.Breath,
table2.Frequency,
(IFNULL(table2.Volume,0) / IFNULL(table2.Area,0)) as 'Volume/Area',
//I don't understand what do you need in this field,
//I don't understand what do you need in this field,
table2.Area,
table2.Volume
FROM table1
JOIN table2
ON table1.Name = table2.Name AND table1.Month = table2.Month AND table1.Year = table2.Year
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
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.. ?
I have a table that holds timestamped messages from a sender to a receiver, and it looks like:
mes timestamp sender receiver
10 2014-04-13 12:22:25.000 1 72
10 2014-04-13 12:22:25.000 1 91
10 2014-04-13 12:22:25.000 1 58
16 2014-02-20 20:09:06.000 3 35
16 2014-02-20 20:09:06.000 3 54
17 2014-03-05 14:55:28.000 1 65
18 2014-03-07 14:55:28.000 2 97
19 2014-03-09 14:55:28.000 2 97
My table holds 3 millions rows like these, and I am trying to group results according to timestamp intervals, counting the number of messages in each month between each pair of sender-receiver. Something like:
timestamp sender receiver count
2014-04 1 72 1
2014-04 1 91 1
2014-04 1 58 1
2014-02 3 35 1
2014-02 3 54 1
2014-03 1 65 1
2014-03 2 97 2
I really have no clue how to specify my clause in mysql, so I apologize for not providing a snippet of my not-working code... should I use something as a switch control and manually specify the time interval? or is there something more specific in mysql to manage tasks like this?
This is fairly straight-forward GROUP BY with multiple levels:
SELECT CONCAT(YEAR(tstamp),'-',MONTH(tstamp)) as tstamp, sender, receiver, COUNT(*) AS cnt
FROM yourtable
GROUP BY YEAR(tstamp), MONTH(tstamp),sender,receiver;
I'm using tstamp as field name for "timestamp" to avoid conflicting with reserved words (timestamp).
I am pretty new to mySQL and I have had a hard time over the past 2 days trying to get this to work. I do not know if the title is correct in relation on what I am trying to fix, but if it is not, please correct me.
Here is the deal:
I have 4 columns... id, number, package_id, and date.
id - Increments every time a new row is inserted
number - Just a 2 digit number
package_id - ID of package
date - date and time row was inserted
Here is what an example table looks like: (I omitted the time from the date)
id number package_id date
--- ------ ---------- ----
1 12 20 08-01-2013
2 12 21 08-01-2013
3 12 20 08-01-2013
4 45 20 08-02-2013
5 45 22 08-02-2013
6 45 22 08-03-2013
7 12 20 08-03-2013
8 70 25 08-03-2013
9 70 26 08-03-2013
10 70 25 08-03-2013
Not only am I trying to select distinct for number and group by date. I am also trying to make sure it does it for each unique value in the package_id column.
To better explain, this is what i want the output to be like when I SELECT *:
id number package_id date
--- ------ ---------- ----
1 12 20 08-01-2013
2 12 21 08-01-2013
4 45 20 08-02-2013
5 45 22 08-02-2013
6 45 22 08-03-2013
7 12 20 08-03-2013
8 70 25 08-03-2013
9 70 26 08-03-2013
As you can see only row 3 and 10 did not get selected because of the same number and package_id together within the same day.
How can I accomplish this?
Is this what you are looking for:
SELECT MIN(id), number, package_id, date
FROM MyTable
GROUP by number, package_id, date
It certainly satisfies your expected result set.