How to remove "middle-process" data from a table? - ms-access

I have this machine where you can process a material over and over until it becomes a product.
The INPUT of the machine looks like this:
DateI Code #Orderofday
-----------------------------
25/02/2019 A0001 1
25/02/2019 B0001 2
27/02/2019 B0002 1
28/02/2019 A0002 1
01/02/2019 B0004 1
01/02/2019 B0003 2
01/02/2019 B0005 3
And the OUTPUT looks like this:
DateI Code #Orderofday
-----------------------------
25/02/2019 B0001 1
25/02/2019 B0002 2
27/02/2019 B0003 1
28/02/2019 B0004 1
01/02/2019 B0005 1
01/02/2019 WINSOR 2
01/02/2019 APRSHA 3
As you can see from the tables, A0001 in the INPUT is processed to become B0001 in the OUTPUT. And then B0001 becomes the INPUT and get processed again to become B0002 etc.
The starting material has a Code column that always begins with a letter "A" followed by 4 numbers, the middle-process always begins with "B" followed by 4 numbers, and the final product are other combination of letters. There is no fixed amount of middle-processes a material has to go through to become a product.
I want to get rid of the middle-process (the Code that starts with "B") to make the final result to look like this:
matco product
-----------------
A0001 APRSHA
A0002 WINSOR
Is there anyway to do this? Much appreciated

Related

Trying to use mysql to exclude certain ones

I'm fairly new to mySQL. I have a table that is supposed to be mutually exclusive between fields labeled "b" or "s", but they aren't. Some fields in column tn have "b", and another field has "s" but they both have the same "tn". This is a data issue I'm waiting for someone to fix. In the meantime, I need to exclude from my "b" query, any items where "tn" would also be in the similar "s" query. My query just has the "b" ones in it, how do I compare against the "s" ones and exclude the crossover errors? Also, I want to exclude any "b" ones with a "tn" count over 2. I know they need to fix the data, but while I'm waiting the months that will take, I want to get a set of data to start with, that is clean. I need the returned row to include all columns shown.
The Table hardware_data looks like this:
tn hardware_item shelf slot port type model
12345678 abcdefg 1 1 1 b Model1
23456789 bcdefgh 1 2 3 b Model1
23456789 bcdefgh 1 2 3 s Model1
34567890 cdefghi 1 1 4 s Model1
12345678 abcdefg 1 1 4 b Model1
12345678 abcdefg 1 1 3 b Model1
45678901 defghij 1 1 2 b Model1
45678901 defghij 1 1 3 b Model1
So in the above data, I would use the following query:
select hardware_item, tn, shelf, slot, port
from accessInventory.hardware_data
WHERE model= 'Model1'
AND type = 'b'
AND CHAR_LENGTH(tn)>3
AND tn*1 = tn
LIMIT 100000;
And it returns this data set
tn hardware_item shelf slot port type model
45678901 defghij 1 1 2 b Model1
45678901 defghij 1 1 3 b Model1
23456789 bcdefgh 1 2 3 b Model1
12345678 abcdefg 1 1 4 b Model1
12345678 abcdefg 1 1 3 b Model1
12345678 abcdefg 1 1 1 b Model1
But I want it to exclude the ones with a duplicate count "tn" over 2 like 12345678 , and ones that cross-over with the "s" category, like 23456789. I don't even know where to start with the cross-over one, and my count over 3 exclusion isn't working because it's comparing the entire row returned and not just the "tn". Any help would be greatly appreciated.
I've googled it of course, but I'm not finding anything for the exclusion I need, and I haven't found this specific case for excluding ones where count of common row items exceeds a value.
Note, can't use "Group By" because it's valid to have 2 tn's matching in "b" category.

MySQL join query for multiple matching conditions

First off, I apologise for the vague title.. I will update it to better reflect my question if anyone has a suggestion, but for not I do not know how to categorise this topic:
I have a few tables storing information for some device. The tables are organised as shown below. The dev_prop table has some properties which are also components. Components have properties stored in the comp_prop table on the right. Other device properties like "color" do not have any more properties associated with them, just a value.
device dev_prop comp_prop
name id name value id dev_id name value id dp_id
dv1 1 comp1 aaa 1 1 height 30cm 1 1
dv2 2 comp2 bbb 2 1 height 20cm 2 2
dv3 3 color red 3 1 height 20cm 3 4
comp1 ccc 4 2 weight 300g 4 2
comp2 aaa 5 2 weight 250g 5 4
color blue 6 2 weight 99g 6 1
color pink 7 3
I want to query the database to select all components that have height 20cm, but I also want to get their weight properties in a separate row. All rows I retrieve should have one comp_prop.value, and only one.
In the sample data above, this would apply to dev_props with id's 2 and 4, because these have heights of 20cm. I would like 4 rows return then, two for their heights, and other two for their weights.
For example, I would like to retrieve rows like this:
select device.name, dev_prop.name, dev_prop.value, dev_prop.id,
comp_prop.name, comp_prop.value from comp_prop
inner join dev_prop on comp_prop.dp_id=dev_prop.id and ......
device | dev_prop.name | dev_prop.value | dev_prop.id | comp_prop.name | comp_prop.value
dv1 comp2 bbb 2 height 20cm
dv1 comp2 bbb 2 weight 300g
dv2 comp1 ccc 4 height 20cm
dv2 comp1 ccc 4 weight 250g
Wondering if you considered nesting the query? First here's the nest:
SELECT dp_id FROM comp_prop WHERE height = '20cm'
Which would give you the dp_id of all items with certain attribute, which can be shoved into conditional like so:
SELECT * FROM comp_prop WHERE dp_id IN (...)
And then just join the other three tables together

Microsoft Access query combine multiple records by ID

I am using Access 2007 on windows 7 Enterprise
I apologize if this has been covered, but I couldn't find it.
In a table where i have:
ID.....info.... place.... because
1..... abc ... home..... fridge
1 .... abc ... work....... desk
1..... abc.... play....... pockets
I would like a query that the result is
Id.. info....as1 .... as1...... as2..... as2 .... as3 ... as3
1....abc...home...fridge... work... desk... play.. pockets
the number of results by ID may vary, and the "Place and because" may not be the same.
any help is greatly appreciated
Thanks in advance
First, you need a column that uniquely identifies each row:
ID info place because id
1 abc home fridge 1
1 abc work desk 2
1 abc play pockets 3
Then, a union query to have all the records in a single column:
ID info rowID key value name
1 abc 1 place home as_1_place
1 abc 1 because fridge as_1_because
1 abc 2 place work as_2_place
1 abc 2 because desk as_2_because
1 abc 3 place play as_3_place
1 abc 3 because pockets as_3_because
Then you want a crosstab query on the name field
ID info as1_place as1_because as2_place as2_because as3_place as3_because
I will elaborate on this shortly.

Join multiple table and sort the result

This is the first question i post in stackoverflow. Hope that you guys can help me resolve this problem. I have been stuck for 2 days.
I have 6 tables. It's all below:
students:
id name lastname
1 John Snow
2 Sansa Stark
3 T-Bag Bagwell
student_course:
id student_id course_id course_start course_end
1 1 1 2015-06-19 2015-08-20
2 2 3 2015-07-09 2015-09-15
3 3 1 2015-05-15 2015-08-22
payment:
payment_id student_id course_id
1 1 1
2 2 3
3 3 1
payment_initial:
payment_id payment_due
1 2015-06-12
3 2015-05-08
payment_installment:
payment_id payment_due int_payment_due
2 2015-07-02 2015-07-15
passport_visa:
student_id passport_expiry_date visa_expiry_date
1 2015-09-10 2015-10-12
2 2015-09-12 2015-09-15
3 2015-10-11 2015-9-28
And the result i want is: result will be sort by date combined form 3 tables which have "Date" field. "Date" field after sorting include only date after present.
How can I make query string that bring me the result like this:
student_id(1) course_id(1) course_start(2015-06-19)
student_id(2) course_id(3) payment_id(2) payment_due(2015-07-02)
student_id(2) course_id(3) course_start(2015-07-09)
student_id(2) course_id(3) payment_id(2) int_payment_due(2015-07-15)
student_id(1) course_id(1) course_end(2015-08-20)
student_id(3) course_id(1) course_end(2015-08-22)
student_id(3) passport_expiry_date(2015-09-12)
.....
I want to add Name and Lastname at the result but it show too long. So I just write like that.
Last result i want to get is the date field (sorted), and which event of date will happen (course start, course end, payment due...)
Sorry if my English grammar is bad. Please help me. Thank you all.
I just collect all result after insert data (which has date field) into one table, and sort them in that table. That makes more insert query but easy to sort.
So I do it on that way.

MS Access pie charts - base query advice?

I have some data that I want to display in a chart:
Theme Type Count(Type)
Blah1 1 5
Blah1 2 5
Blah1 3 8
Blah2 1 1
Blah3 2 5
Blah3 3 10
Blah4 1 111
Blah4 2 222
Blah4 3 333
I want to display that query data in a Pie Chart, one chart for each theme with a section of pie for each Type (with the value of the count determining the size). Unfortunately my mind has gone blank. Everything I try does not appear correctly, some queries also require an repeated entry of the parameters but even if I do that it doesn't display correctly. I think I need to write another query to the format:
Theme Type1 Type2 Type3 Type4
Blah1 5 5 8 1
Blah2 1
Blah3 5 10
Blah4 111 222 333
Is that correct and does that make sense? If it isn't correct how else do I do it?
I haven't done charts before and I am struggling a bit - many thanks for any help.
Try to put your data in columns. This is what I did. You can see the selection I had when I inserted the pie chart:
For more charts you can either copy the data and just replace the last column with the numbers. Or you could also copy the inserted chart and change the source data (when you click on the pie part you see the source data in the worksheet - you can drag it to a new area).
I ended up creating a crosttab query to produce the data in the following format, as you suggest it needed to be in the similar column layout:
Theme Type1 Type2 Type3 Type4
Blah1 5 5 8 1
Blah2 1
Blah3 5 10
Blah4 111 222 333
I am relatively experienced with Access - just not charts unforunately!! Seems so simple :(