I have an issue. I have database about 588k rows. Database is about pharmaceutical sales.
Problem is, that we have historical pharmacies that are opened=valid or closed=deleted. BUT one customer number can have both states due to changing adress, ZIP-code, etc.
Like this:
name
Register State
Customer Code
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Valid
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Valid
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Deleted
***979
Lékárna NEMOCNICE TÁBOR
Valid
***979
In this situation I'd like to keep only valid according to Customer code.
But it can happen that we have historical pharmacy, which is not valid anymore, but I want to keep it anyway, because we have historical settings on it.
Like this:
name
Register State
Customer Code
ARLEGO
Deleted
***169
And we no longer have any record of it. Just this one.
Do you have any idea how to solve this problem or even have any queries, that would help me?
Final result would be something like this.
name
Register State
Customer Code
Lékárna NEMOCNICE TÁBOR
Valid
***979
ARLEGO
Deleted
***169
I'm not exactly sure of your requirements, but perhaps something like this:
select *
from (
select customerNo, pharma, state
, row_number() over(partition by customerNO, pharma order by case when state = 'valid' then 0 else 1 end) as sort
from pharmacy c
) c
where c.sort = 1
This will fetch one row per customer/pharma combo, prioritized by the valid row, but will also get the deleted row if there are no valid ones.
I'm not sure if you also want to sort the stuff by dates, but then one can just add that into the row_number over sort.
Related
I'm trying to subtract a value in one field from a value in another table, depending on ID number using Filemaker Pro 19.x. I thought I'd done this before without any problems but now it isn't working and I don't know why.
First, I want to do this in a calculation field, not in a script. I don't understand scripting at all and use it only when there is no alternative. In this case, I think a calculation field should work.
I have 2 tables, I'll call them "Data" and "Categories"
Both tables have the field "CID" "Category ID".
The CID fields in both tables are linked in the Relationship Editor
The Data table has a field "Product ID"
The Categories table has several fields related to products. Two of those are "MIN PID" and "MAX PID". These are the minimum and maximum product ID numbers.
Product IDs are assigned in ranges. If it is within a certain range, it has to belong to a certain category. These categories have CID numbers.
To assign the CID number to the products listed on the Data table, I did run a script that essentially recreated all the data within the Categories table. It was inefficient (in my eyes) because the data was sitting right there in the table. I couldn't figure out how to reference it, so I gave up and ran the script instead. The other problem is that if the CID ever changes for a product, I have to rerun the script (or someone else, who might not know about the script)
That said, I now have the correct CID assigned for all 62 product categories. What I want to do now is to use the CID MIN and CID MAX values (among others) in calculation fields in the Data table.
For instance, if the product ID is "45,001", it belongs to the Category "16", which has a MIN value of "30,000" and a MAX value of "50,000". I want to subtract the "30,000" from the "45,001", (PID - CID MIN) to return the result "15,001". This allows me to locate a product within the category. Instead of being "Product 45,001", it will be "Product 16.15001".
The calculation I tried is:
If (CID = CID::CID ; PID - CID::CID MIN)
The result is a huge group of records where this field is empty.
I also tried:
PID - CID::CID MIN
Again, no results.
Both tables have the field "CID"
The two CID fields are linked in the relationship editor.
I have tried this with a test file and it works perfectly. It does not work in the database I am working within.
What am I doing wrong?
I'm decent when it comes to working with Access, and can usually figure things out but am currently stumped on this query process.
I only have 2 shipment tables. One contains historical data (tblBookedLoads), while the second table (RMCData) contains current orders.
What I need to do, is for each row in RMCData, figure out who has driven the same route recently (Origin to Destination) and send them an email with the details of the matching shipments... and any others that match, IE, if I have 50 shipments from Atlanta to Memphis tomorrow, I don't want to send them 50 emails.
I'm just not sure about how to go about retrieving the information since it it stored in different formats, or how to create a query based on row by row data from fields in another table... Let me know what you think. I'm guessing it has something to do with looping in vba, but not sure.
Both tables are read only.
tblRMCData 'Contains details for new orders (approx. 1000 rows)
' has fields 'ReferenceNum','Ship Date','Origin City', 'Origin State','Origin Zip','destination', 'Weight','Comments","Comments2"
'Origin/Destination City, State and Zip are separated
tblBookedLoads 'contains history of orders (approx. 20000 rows). CONTAINS DUPLICATES
' has fields 'Carrier', 'Ship Date", 'Order','Origin', 'Destination','Weight','Bill Amount",'email address'
' Origin/Destination is populated as "LITTLE ROCK, AR 12345"
Any advise is appreciated.
I have thousands of daily report spreadsheets from a number of locations that include a list of each staff member working that day. Unfortunately the reports are not easy to sort into chronological order from the filename or the creation date. I will be using .Net to populate SQL Server tables with the data.
My aim is to be able to produce a report that looking like this, showing the 2 weeks (might be more or less) that each person worked:
'Worker 1' 'Location A' 2016-04-05 to 2016-04-19
'Worker 2' 'Location A' 2016-04-19 to 2016-05-03
'Worker 2' 'Location B' 2017-01-01 to 2017-01-14
'Worker 2' 'Location A' 2017-02-01 to 2017-02-14
Unfortunately, as each report is processed, all I know is the location and a list of people that were there on the day. So, I don't know until later whether a person has finished their 2 weeks or not.
My question is - what is the best structure to store the data to allow analysis?
I thought of 1 record per location and worker, with start date & end data, but this won't work if Worker 1 works at Location A for 2 weeks, has 2 weeks off and comes back to the same location, as I would want to present that in my report as 2 sessions of work.
I also considered 1 record per day per location with 1 field per worker but this would get messy as workers came on & off hire.
I also considered 1 record per worker per location with 1 field per day but I already have 3 years worth of reports so the amount of fields will get unwieldy.
Is there a good way to record the initial data to be able to extract as I want it for analysis? Or should I just pre-process the daily reports to ensure they are processed in chronological order before writing them into tables?
I am working with a site using cakephp 1.3. Last month i have changed hosting service of the site. After that i am having a issue.
ie. I have bookings table in my DB. When i am using find() statement, bookings table returns double entry. I could not find why this is happening.
For example, I got the vehicle data of the particular place returns the below,
when i use 'recursive'=>2 in find('all') statement ,I got the following
**
Parking Location : Chennai Citi Centre 2W
Booking Date : 02/04/2013
Booking ID Transaction Type Vehicle No Check In Date Check Out Date
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
**
But when i use 'recursive'=>-1 in find('all') statement,I got the following
**
Parking Location :
Booking Date : 02/04/2013
Booking ID Transaction Type Vehicle No Check In Date Check Out Date
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
**
Here parking location is not coming. Its in providers table.
Please anyone help me to fix this
Normally I wouldn't recommend using anything other than recursive=>-1, and just use containable behavior when appropriate.
I can't really tell you why the first approach returns double entries without knowing the models associations, or having the exact find query you're using (are you doing a find() with the Bookings or the Parking or what else :S ?), but try and use containable and see if it works.
Something like... (I'm just going to assume how your models are called and how you're using find())
$this->Booking->find('all', array('conditions'=> array() ,//some conditions here
'recursive' => -1,
'contain' => array('Parking'));
After that, do a dump of the returned array to see if the output fits your needs. For more of containable behavior check here.
Imagine an ecommerce platform that works as follows:
A Package, consists of a mixture of Items and other Packages.
An Order consists of a mixture of Items and Packages.
A user can select some items, and some packages to order, but can also go ahead and remove some items from a package as part of that order, this doesn't affect the original package.
A Package can change in the future, but the Order must show what was actually ordered as part of the packages at the time.
Here is an example:
Package_A: [Large_Knife, Cutting_Board]
Package_B: [Cheese, Package_A]
Order_1: [Wine, Small_Knife, (Package_B - Large_Knife)]
Now lets say Package_A changes to:
Package_A: [Large_Knife, Cork_Screw]
Which means the new Package_B has a Cork_Screw instead of Cutting_Board.
When the user looks at his old order he should see what he actually ordered.
Order_1: [Wine, Small_Knife, Package_B([Cheese, Cutting_Board])]
There is no need to store/show that Large_Knife was removed if that makes it easier to model.
Would love to hear ideas on how to model this.
Thanks.
An Item can be in many Packages.
A Package can contain many Items.
An Order can have many Items and Packages.
A Package or Item can be in many Orders.
A User can place many Orders.
A Order is placed by one User.
Package's items can change over time, but there´s no need to track this changes.
If a Package changes, Orders containing that Package should not be affected, and its content should remain as it was by the time it was ordered.
Proposed Model:
User: UserId(PK), LastName, FirstName, Email
Item: ItemId(PK), Description
Package: PackageId(PK), Description
PackageDetail: PackageId(FK), ItemId(FK)
Order: OrderId(PK), UserId(FK), DateOrdered
OrderDetail: OrderId(FK), ItemId(FK, not null), PackageId(FK, "0" if it's an Item)
If the Order contains an Item, field ItemId on table OrderDetail must contain its PK, and PackageId must be set to "0".
If the Order contains a Package, containing 3 items by the time it was placed, you must insert 3 rows on table OrderDetails, all with the same PackageId but with different ItemdId.