Im currently building an interface with PHP and MYSQL with all my salon services and everything was fine till I had to add my waxing services:
When talking about waxing you can have every combination between these group:
Lips
Chin
Face
Underarms
Arms
Eyebrows
None of the above
Also one of these:
Half Leg
Full Leg
No Legs
And one of these:
Small Bikini
Big Bikini
Brasilian
No Bikini
So, I was thinking on doing the first part on binary until I figure out that just on the first part I had 128 combinations, plus 3 different variations on the next group(Legs) and 4 more under the bikini area.... This makes a total of 2048 possible combinations?? so that means that I will have to fill a DB with 2048 different descriptions, prices and services codes(the most important column)
So This is when I know that im doing something wrong here(regarding the method) and I need your help to know how is this done from the BD point of view. After all I just need a service code that will allow me in the future to differentiate each service from the other one.
And if this is the real way of doing it, how or what do you use to generate the 2000+ rows with the data?
Thanks
How would you do this if you weren't using software? If a client came and asked for, say, eyebrows, arms, and full legs....
Would you say eyebrows are $3, arms are $6, and full legs are $10?
If so, you can create yourself a data base row for each particular service you offer, and allow your client to choose any combination of products.
This involves a many-to-many relationship between your client and your service tables. In RDMSs like MySQL, you'll need a client table, a service table, and a client_service table. The third of those contains pairs of numbers, client_id and service_id, and perhaps a date. If you want to know what services a certain client had yesterday, you could, for example, use a query like this
select cs.service_time, c.name, s.service
from client c
join client_service cs ON c. client_id = cs.client_id
join service ON cs.service_id = s.service_id
AND DATE(cs.service_time) = CURDATE() - INTERVAL 1 DAY
where c.name = 'Jane'
The point of the client_service table is to allow you to associate multiple clients with each service, and multiple services with each client. This is a far better software design choice than the combinations you mention, which will soon outnumber the hairs on your clients', umm, heads.
The user interface for this kind of table will present a list of the services you offer (the rows in your service table) with a checkbox next to each one.
As you wait on each client, you'll check the services you deliver. Then your software will create a row in your client_service table for every check on the list.
If your service table contain a price for each service, you can retrieve those prices as follows.
select DATE(cs.service_time), c.name, s.service, SUM(s.price) AS price
from client c
join client_service cs ON c. client_id = cs.client_id
join service ON cs.service_id = s.service_id
AND DATE(cs.service_time) = CURDATE() - INTERVAL 1 DAY
where c.name = 'Jane'
group by c.name, DATE(cs.service_time), s.service WITH ROLLUP
Related
I have a problem with acces, im trying to make database of airport and cant realy make one to one - one to one - one to one connection beetwen ticket, passanger and luggage. The idea is that one passanger can have one ticket and one luggage, and when im doing it like it is on picture i cant acces luggage from ticket neither from passanger only from luggage itself.
My diagram
Mainly the diagram should be something like:
Simple Data and Keys:
Sample query(all tickets with relevant linked data):
SELECT Tickets.Ticket,
Tickets.Person,
Flights.Flight,
Luggages.Luggage
FROM Flights
INNER JOIN (
(Persons INNER JOIN Tickets ON Persons.ID = Tickets.Person)
LEFT JOIN Luggages ON Tickets.ID = Luggages.ID)
ON Flights.ID = Tickets.Flight;
Second view was the purpose, so it up to your side to do the adjustments.
Note:
Person 3 do not have luggage.
Person 1&2 use same flight.
MS Access was used, but design is not bound to a specific rdbms (only dialects adjustments for a particular implementation)
Also, there is an error on relation Persons-Tickets which should be 1-n.(similar Flight-Tickets).
Still additional constraints could be bound also.
Eg: a person can be just on one flight is a specific time.
I'm looking for a way to make a database for equipment managment but I don't know how to go forward from my point.
I have now 3 core tables to do this part, the EQUIPMENT table, where I have a list of all the equipment I have (with the different units on record and everything),
besides this one I have the PROJECT table, where I have all the information of the rental service and I also have a PROJECT_DETAILS where I place the equipment for the given project
Examples:
EQUIPMENT TABLE: Brand,Model,Internal Number:
[Ford;Transit; 1][Ford;Transit;2][Ford;Transit;3][Mercedes;Sprinter;1][Mercedes;Sprinter;2] Etc...
PROJECT TABLE: Project code, Start, End, Client Name:
[XX001;2016/08/05;2016/08/10;Steve][XX002;2016/08/06;2016/08/8;Bill] etc...
PROJECT DETAILS: Project Code, Equipment, Internal Number:
[XX001;Transit;1][XX001;Transit;2][XX002;Transit;3][XX002;Sprinter;1]
So what I want to do is when trying to make a new project, I want the equipment to dissapear from its combo box if the equipment is in use in another project
I would continue to flesh out the database schema with the following additional tables:
RENTAL: This represents "the rental contract itself." The rental might be active, or it might be being contemplated. Perhaps, all RENTALs belong to (one) PROJECT ...
RENTAL-EQUIPMENT: This one-to-many table lists the items that are to be rented when this rental contract goes into effect.
RENTAL-EQUIPMENT-RESERVED-NOW: This is “where the rubber hits the road.” This table contains an entry for every piece of EQUIPMENT that is "right now, irrevocably, 'off the lot.'" It is related both to RENTAL-EQUIPMENT (to justify the presence of the record), and directly to EQUIPMENT ("where's that dump truck and why is it not here on the lot? Oh. We rented it. I see..."). I'd probably insert a record into the table when the equipment went out the door, and remove the record when the equipment was returned. The presence of a row in this table ... only one row per equipment_id is allowed ... is sufficient to indicate that a piece of equipment is reserved or off-the-lot, and why.
In this view of things, PROJECTs, from time to time, "rent things," or "plan to rent things in the future." (Nobody rents anything unless it is associated with a project, say...) Each RENTAL consists of a list of equipment to be rented. Then, when stuff goes off-the-lot and we need to be able to quickly(!) account for it (without poring through a bunch of RENTAL-EQUIPMENT and RENTAL records in a very-laborious query ...), the RESERVED-NOW table gives us an immediate answer.
You should also familiarize yourself with the concept of TRANSACTIONs, which Access fully supports. A "transaction" is an atomic group of SQL statements that will be "all or nothing." For instance, when you start to process the departure of a piece of equipment from the lot, you "start a transaction." Then, you perform the SQL statements needed to insert into RENTAL-EQUIPMENT-RESERVED-NOW and to update RENTAL-EQUIPMENT records and so-on ... then, you "COMMIT the transaction." All of the changes that you made, all at once, then "become permanent."
What? "Oopsie! Something went wrong!!" No problem: just ROLLBACK the transaction instead, and you're right back where you started. Nothing that you did during the transaction 'actually happened.' (Rollbacks often appear in on error goto... blocks.)
Finally, also look at things like "foreign keys" and "referential integrity."
I think something like this would work. Basically depending on on how your project is set up, you would want to look at anything where the end date is past your current client trying to schedule "schedule_date" let's say and before or equal to the schedule_date. This way if they select a date range, anything that is between those dates wouldn't show up.
SELECT * FROM equipment WHERE internal_number NOT IN (SELECT internal_number FROM project INNER JOIN project_details ON product_details.project_code = project.project_code WHERE end_date >= schedule_date and begin_date <= schedule_date)
From the way I read your question, it sounds like ProjectDetails is recording the combinations of the project and the equipment. It also sounds like you aren't interested in keeping a historical of those assignments, and are therefore removing them from projectdetails when they are no longer assigned.
So (again, if I understand correctly), what you want to do is to show all of the records in the equipment table that does not exist in the projectdetails table - correct?
SELECT * FROM equipment INNER JOIN projectdetails ON equipment.equipid = projectdetails.equipid
I broadly concur with DHW and Mike Robinson - From my reading of your structure you are using the project details table as a junction table to relate the equipment and the projects. Comparison of this table to the equipment should give a list of all unused equipment.
I had a go on an access database at my end and I joined the Equipment Table to the Project Details Table and did a left join so that ALL equipment was shown. I then added the Equipment field of the Project Details table. In order for this to work you need a relationship between the Project Details Table and the Equipment table and you must ensure the Project Details Equipment Field and the Equipment Table Internal Number are same data type ie Long Integer. I then ensured then put a filter on the Project Details.Equipment field criteria set to Null. The SQL I used for this was
SELECT EquipmentTable.InternalNumber, EquipmentTable.Brand,EquipmentTable.Model, ProjectDetails.Equipment FROM EquipmentTable LEFT JOIN ProjectDetails ON EquipmentTable.InternalNumber = ProjectDetails.Equipment WHERE (((ProjectDetails.Equipment) Is Null));
I'm creating an Intranet for my company, and we want to have a stock management in it. We sell and rent alarm systems, and we want to have a good overview of what product is still in our offices, what has been rented or sold, at what time, etc.
At the moment I thought about this database design :
Everytime we create a new contract, this contract is about a location or a sale of an item. So we have an Product table (which is the type of product : alarms, alarm watches, etc.), and an Item table, which is the item itself, with it unique serial number. I thought about doing this, because I'll need to have a trace of where a specific item is, if it's at a client house (rented), if it's sold, etc. Products are related to a specific supplier, to whom we can take orders. But here, I have a problem, shouldn't the order table be related to Product ?
The main concern here is the link between Stock, Item, Movement stock. I wanted to create a design where I'd be able to see when a specific Item is pulled out of our stock, and when it enters the stock with the date. That's why I thought about a Movement_stock table. The Type_Movement is either In / Out.
But I'm a bit lost here, I really don't know how to do it nicely. That's why I'm asking for a bit of help.
I have the same need, and here is how I tackled your stock movement issue (which became my issue too).
In order to modelize stock movement (+/-), I have my supplying and my order tables. Supplying act as my +stock, and my orders my -stock.
If we stop to this, we could compute our actual stock which would be transcribed into this SQL query:
SELECT
id,
name,
sup.length - ord.length AS 'stock'
FROM
product
# Computes the number of items arrived
INNER JOIN (
SELECT
productId,
SUM(quantity) AS 'length'
FROM
supplying
WHERE
arrived IS TRUE
GROUP BY
productId
) AS sup ON sup.productId = product.id
# Computes the number of order
INNER JOIN (
SELECT
productId,
SUM(quantity) AS 'length'
FROM
product_order
GROUP BY
productId
) AS ord ON ord.productId = product.id
Which would give something like:
id name stock
=========================
1 ASUS Vivobook 3
2 HP Spectre 10
3 ASUS Zenbook 0
...
While this could save you one table, you will not be able to scale with it, hence the fact that most of the modelization (imho) use an intermediate stock table, mostly for performance concerns.
One of the downside is the data duplication, because you will need to rerun the query above to update your stock (see the updatedAt column).
The good side is client performance. You will deliver faster responses through your API.
I think another downside could be if you are managing high traffic store. You could imagine creating another table that stores the fact that a stock is being recomputed, and make the user wait until the recomputation is finished (push request or long polling) in order to check if every of his/her items are still available (stock >= user demand). But that is another deal...
Anyway even if the stock recomputation query is using anonymous subqueries, it should actually be quite fast enough in most of the relatively medium stores.
Note
You see in the product_order, I duplicated the price and the vat. This is for reliability reasons: to freeze the price at the moment of the purchase, and to be able to recompute the total with a lot of decimals (without loosing cents in the way).
Hope it helps someone passing by.
Edit
In practice, I use it with Laravel, and I use a console command, which will compute my product stock in batch (I also use an optional parameter to compute only for a certain product id), so my stock is always correct (relative to the query above), and I never manually update the stock table.
This is an interesting discussion and one that also could be augmented with stock availability as of a certain date...
This means storing:
Planned Orders for the Product on a certain date
Confirmed Orders as of a certain date
Orders Delivered
Orders Returned (especially if this is a hire product)
Each one of these product movements could be from and to a location
The user queries would then include:
What is my overall stock on hand
What is due to be delivered on a certain date
What will the stock on hand be as of a date overall
What will the stock on hand be as of a date for a location
The inventory design MUST take into account the queries and use cases of the users to determine design and also breaking normalisation rules to provide adequate performance at the right time.
Lots to consider and it all depends on the software use cases.
I got a huge performance issue for my uploading data into mysql db. Using an example, I have special tools to mine say personal information of thousands of people.
I have one tool that mines the phone numbers of the people. Another that mines say the home address of the people. Another mines the photos of the person. So for this example, say there are 100000 people of Country A. I will have to mine data from different countries later on. These mining tools will finish at different times. The mining of phone numbers takes 20 mins. Mining of photos takes 1 week. Mining of the addresses takes 3 days.
The customer wants to see the data as soon as possible in an existing table/db. I wrote some scripts to detect when one tool finishes to start uploading row by row data. However, this seems to take a REALLY long time (using UPDATE ...).
Is there a faster way to do this?
The table that exists in the db is structure like this:
Columns: ID_COUNTRY,ID_PERSON,FULL NAME,PHONE,BLOB_PHOTO,ADDRESS
Yes, there is a faster way. Put the data from each of the processes into a separate table, by inserting into the table.
You will then have to create a query to gather the data:
select *
from people p left outer join
phones ph
on p.personid = ph.perhsonid left outer join
addresses a
on p.personid = a.personid left outer join
photos pho
on p.personid = pho.personid;
Each individual table should start off empty. When the results are available, the table can be loaded using insert. This has at least two advantages. (1) inserts are faster than updates, and bulk inserts may be faster still. (2) The data is available in some tables without blocking inserts into the rest of the tables.
So I am working on an Invoicing Report in SSRS 2008. The database contains 4 relevant tables:
- Work Order
- Labor
- Materials
- Services (Subcontractors)
Obviously the work order table contains all the relevant information about the overall work order (we display things such as location, priority, etc). For this invoice report, I need to display the work order details up at the top, then show the labor, materials, and services used on the work order (with totals for each), then show a complete total for the entire cost of the work order.
My issue is this: I can do a dataset that works with Work Order + any ONE of the child tables, however I cannot figure out how to do all 3! I can't simply do a parameter for WONUM with 3 (or 4) tables on it, because this report will have MANY work orders (one per page) on it. When I use a dataset with the Work Order table and one child table, I group by WONUM then do a page break between each instance.
Any ideas for how to handle it? Most answers I came across say make one gigantic "union all" dataset and then group it after that, or use subreports for each child table. However, we will be exporting this report to Excel, and I've been told that subreports do not render properly when exported.
Any and all help is greatly appreciated! Thanks!
EDIT:
Below are the 4 queries I'd LIKE to use:
This retrieves all the work orders that need to be billed:
SELECT wonum, description, location FROM workorder WHERE billable=1 AND status='COMP'
This retrieves the labor for a work order (specified by #wonum)
SELECT regularhrs, laborrate, totalcost FROM labor WHERE refwo=#wonum
This retrieves the materials for a work order (specified by #wonum)
SELECT description, quantity, unitcost, totalcost FROM material WHERE refwo=#wonum
This retrieves the services (subcontractor hours) for a work order (specified by #wonum)
SELECT description, hours, laborrate, totalcost FROM service WHERE refwo=#wonum
So as I stated in the original post, my first query retrieves all the work orders that need to be billed, then for each work order (one per page), I need to retrieve the labor, materials, and services and display it in 3 tables below the work order details, then put an overall total cost on the work order invoice (at the end of each work order, not the end of all work orders)
I can get a screenshot of my current report if that would help also. Just let me know in comments!
Your query should look something like this
SELECT WO.wonum, WO.description as WorkorderDescription, WO.location, L.regularhrs, L.laborrate, L.totalcost,
M.description as MaterialDescription, M.quantity, M.unitcost, M.totalcost as MaterialCost,
S.description as ServiceDescription, S.hours, S.laborrate, S.totalcost as ServiceCost
FROM workorder AS WO
INNER JOIN labor AS L on L.refwo = WO.wonum
INNER JOIN material AS M on M.refwo = WO.wonum
INNER JOIN service AS S on S.refwo = WO.wonum
WHERE billable = 1 AND STATUS = 'COMP'
This will efficiently gather the information you need into one dataset. You will need to use the grouping features to setup the table in SSRS. You may have to do some additional research if you get stuck on getting the table layout right.