FIFO Data Matching by Each - ms-access

Way out of my depth here - hoping to get help.
I use Access to arrange 3 sets of data. Promise Date, Delivery Date and Production Date to look for On Time Delivery, On Time Production, Etc.
There are no links that pair these 3 tables. We might build 5 pieces and ship 3 to one and 2 to another, so I can't do a lookup based on quantity movement.
Instead, I break each table into "Eaches" by date and match them in a FIFO fashion.
Thus the first unit produced probably belongs to the first unit shipped, etc.
This requires a tremendous amount of manual manipulation, primarily sorting by date and putting back into Access.
Is there a way to take a table, break it into eaches, and sort & count that table by date?
It would take this:
Prod / Date / Qty
X / Jan-10 / 2
Y / Feb-10 / 2
Z / Mar-10 / 2
And turn it into this:
Prod / Date / Qty / Order
X / Jan-10 / 1 / 1
X / Jan-10 / 1 / 2
Y / Feb-10 / 1 / 1
Y / Feb-10 / 1 / 2
Z / Mar-10 / 1 / 1
Z / Mar-10 / 1 / 2
I could link the tables together from there - but can't figure out how to do it outside of Excel sorting and formulas that look at rows above.

Related

MySQL per shift counter query

I'm looking for some advice with a query I'm trying to write. I would like to count the occurrence (number of rows) of a column based on whose shift (6-2, 2-10 & 10-6) it falls into. The trouble is the shifts rotate every two weeks, e.g. if I just started on the 6-2 in two weeks time I would be on the 10-6. I have a query that will count said occurrence depending on the shift but I cannot get my head around how to make it count based on whos shift it happened on.
Any advice would be very helpful!
Thanks in advance.
Edit:
Table headings
Serial Number | Date & Time | Part Number | Type | Result
Edit 2 (a bit more detail):
I would like to count how many instances of unknown occur in part number for each our shifts. The part number column contains various numbers (always length 8) identifying the product running through the machine. If the machine for whatever reason doesn't see or read the part number correctly it writes unknown to the table.
e.g.
Week 13: Tom is on 6-2 shift / Alex is on 2-10 shift / Cam is on 10-6
Week 15: Alex is on 6-2 shift / Cam is on 2-10 / Tom is on 10-6 shift
Week 17: Cam is on 6-2 / Tom is on 2-10 shift / Alex is on 10-6 shift.
This pattern continues indefinitely and I want to some the number of unknowns in part number for Cam's shift, Tom's shift and Alex's shift. So I should end up with three numbers. I hope this helps.
OK, so we can get the week number in MySQL. For instance:
WEEK(<Date & Time colum>, 1)
have a look at the link above to decide which mode you need.
There are three shifts and three workers. I'll give them numbers:
Tom = 0
Alex = 1
Cam = 2
6-2 = 0
2-10 = 1
10-6 = 2
I then get this pattern:
week
shift
worker
rotation
0
0
0
0
0
1
1
0
0
2
2
0
1
0
1
1
1
1
2
1
1
2
0
1
2
0
2
2
2
1
0
2
2
2
1
2
3
0
0
3
3
1
1
3
3
2
2
3
4
0
0
0
Now we need to try and compute the 'shift' and 'worker' numbers from the 'week' number. Let's start with the 'shift'. There is no way to get it from week, we just have to define it:
SET shift0 = 0
SET shift1 = 1
SET shift2 = 2
This seems pointless, but bear with me. Now we need to compute the workers. How would we do this, given the 'week' and 'shift'? Here we have to use modulo 3:
SET worker0 = MOD('week' + 'shift0', 3)
SET worker1 = MOD('week' + 'shift1', 3)
SET worker2 = MOD('week' + 'shift2', 3)
Written full out with the WEEK() function:
SET worker0 = MOD(WEEK(<Date & Time colum>, 1) + 0, 3)
SET worker1 = MOD(WEEK(<Date & Time colum>, 1) + 1, 3)
SET worker2 = MOD(WEEK(<Date & Time colum>, 1) + 2, 3)
This is as far as I am willing to take it.
I would try to reconstruct the missing information using the above and store it in the database. Create tables to hold the workers and the shifts. Otherwise you'll have to write very complicated queries, which is not what you want.

Determine number of factors of a given number without overlap in MySQL

I have a data set with orders of tickets. Tickets can be bought in packs of 5, or 3, as well as individually. I need to group the data using the quantity of tickets sold per order, to determine if it was a 5 pack (divisible by five), then 3 pack, or else/then individually (1 or 2 qty). So if I have a quantity of 27, I know that order consisted of five "5 packs", and 2 individual tickets.
SUM(CASE WHEN (id % 5) = 0 THEN 1 ELSE 0 END) fivepack
I have this in my query, but stringing these together for fivepack, and threepack, doesn't eliminate the starting number from the total quantity on the next operation. So a quantity of 27, would yield a result of 5 "five packs" and 9 "three packs", and then 27 "individuals".
So given a quantity, how would you first divide by a large factor, get the remainder and divide by the smaller, then finally handle the remainder?
Edit:
The sample packs provide a discount of the purchase price(not relevant to the technical issue), so the first maximum division needs to occur first. So as Gordon Linoff asked below, in the case of 27 tickets quantity, you would take the maximum number of 5 divisions first, then pass the remainder to try to divide by 3, and then return the final remainder as individuals.
The issue is passing the value of one operation in SQL to the next operation, so so on. So I can do Math1, pass Answer1 to Math2, and then pass Answer2 to Math3.
I don't fully understand why 27 would be 5 five packs and 2 individuals rather than any of the following:
27 individuals
9 3-packs
4 5-packs, 2 3-packs, 1-individual
8 3-packs and 3 individuals
and so on.
But, if you want a greedy approach, you can use the following arithmetic:
select floor(num / 5) as five_packs,
floor( (num - 5 * floor(num / 5)) / 3) as three_packs,
num - 5 * floor(num / 5) - 3 * floor( (num - 5 * floor(num / 5)) / 3) as singles
Here is a SQL Fiddle illustrating the logic.

Algorithm for selecting tiles outwards center point in a 512*512 map

I've got a specific problem. My data (map) in mysql is as follows
id table_row table_col tile_type
1 1 1 0
2 2 1 0
3 3 1 0
... ... ... 0
512 512 1 0
513 1 2 0
514 2 2 0
515 3 2 0
... ... ... 0
... 512 2 0
... 1 3 0
... 2 3 0
... 3 3 0
... ... ... 0
... 512 3 0
... 1 4 0
Map is 512*512. I need to come up with an algorithm that selects tiles from the centre(or near centre 256*256) point. So it should look something like
256*256 first - once selected we can update tile_type to 1
255*256 second - update tile_type to 1
256*255 third - update tile_type to 1
257*256 fourth - update tile_type to 1
256*257 fifth - update tile_type to 1
etc. or similar, but it has to start filling in tiles from centre outwards in all directions (can be random). Any ideas appreciated
Your question lacks a few details, but I am assuming you are asking a means of generating an id that is close to the center of your 512x512 grid.
It appears your grid is enumerated in a particular manner: each column is enumerated in increasing order of table_row values, and the enumeration of columns is done in increasing order of table_col values.
Consequently, we can already know the id of the cell for which the table_row and table_col values are 256: it is 255 x 512 + 256. That is correct, because there are 255 full columns that were enumerated before enumeration started for table_col value 256, and each of those columns had 512 rows in them. Finally, within this column, we are interested in row #256.
A more generalized version of this would look like below.
((num_cols + 1) / 2 - 1) * num_rows + (num_rows + 1) / 2
You don't need to care all that much about the +1s and -1s: they are just a numerical hack to handle odd num_rows and num_cols values.
Anyways, to introduce a proximity measure, you can just use two random variables. A random variable P can represent the distance to the center in terms of colums. (i.e. how far the table_col of the point with the generated id will be from the table_col value of the center of the grid) Another random variable Q can represent the distance to the center in terms of rows.
((num_cols + 1) / 2 - 1 + P) * num_rows + ((num_rows + 1) / 2 + Q)
Then you can just generate values for P and Q based on your needs, and get the id of a cell that is P colums and Q rows away from the center of the grid.
Try Below query.
SELECT (MAX(t.`row`+1)/2), (MAX(t.`column`+1)/2) INTO #max_row, #max_col
FROM tiles t;
SELECT t.`row`, t.`column`, ceil(IF(ABS(#max_row - t.`row`) < ABS(#max_col - t.`column`), ABS(#max_col - t.`column`), ABS(#max_row - t.`row`))) as tbl_order
FROM tiles t
ORDER BY 3

Vertical Axis in chart repeating values -SSRS 2008 R2

This is my data:
Year / Month / Sales
2012 / 1 / 2496496.82
2011 / 1 / 2618210.62
2012 / 2 / 2451754.51
2011 / 2 / 2268699.08
2011 / 3 / 2810107.42
2012 / 3 / 2621037.55
Serie label properties: Currency, show values in Millions, use 1000 separators, decimal place 2
vertical axis properties: minimun auto, maximun auto, interval auto, interval type auto
and this is what a got in vertical axis:
3
3
2
2
1
1
0
The report showing duplicated values in Y-axis, How can i get rid of the repeating values 3 3 2 2 1 1 ??
I hope someone has the answer, thank you
I think your issue is Y - Axis showing you repeated numbers. Actual issue is it is not showing the decimal places there that means
3
3
2
2
1
1
0
should be like follow
3.5
3.0
2.5
2.0
1.5
1.0
0.0
But it doesn't show decimal places.
To resolve this go to the "Vertical Axis Properties" -> Number tab -> Choose the Category as "Default" while keeping Minimum, Maximum, Interval and Interval Type = Auto in the Axis Option tab.

Retrieve all tags for all results in MYSQL Query

I am working on a video tagging system. I know the unique ID for each video I want in the search result thanks to a previous query I have to run, but what I want to do is show all of the tags for each video in the search result in the listing so it's multiple categories and contributors are displayed without having to click through into the main page.
The code below returns 5 rows for the 2 videos in the search results. I can always loop around that result, but then that means that I can't use the limit functions and I will have to build some php to do that for me.
SELECT * FROM tags
JOIN siteupdates ON tags.item_id = siteupdates.clip_id
JOIN updatetype ON siteupdates.updatetype = updatetype.id_type
JOIN tagnames ON tags.tag = tagnames.tagid
WHERE tags.item_id IN (248,257)
ORDER BY siteupdates.clip_date DESC
Result (this is an example of the first 5 results, and I have cut out most of the columns that aren't relevant)
uid / item_id / tag / updatetype / tagname / tagtype
1560 / 248 / 14 / 1 / tag 14 / Category
1561 / 248 / 3 / 1 / tag 3 / Contributor
1562 / 248 / 7 / 1 / tag 7 / Category
543 / 257 / 43 / 1 / tag 43 / Category
544 / 257 / 3 / 1 / tag 3 / Contributor
Ideally what I need is a 2 row result, but containing all of the tag data.
alternatively, am I just asking for something that isn't possible just with just MYSQL and my original plan to loop around in PHP is the only option? A new query to get the tag info for each result does not sound like a good idea to me as it will be possible to have up to 50 results per page, so 52 queries in total (including one earlier in the script)!
Any help is greatly appreciated.
So if I get you right you want all of the tags, but not one tag per result record but all in one? In this case GROUP_CONCAT() might help.