Creating new table for related data in database - mysql

I have a SQL table Users, with each user having multiple educational institutions. E.g. John may have gone to Harvard in 2019, Oxford in 2020 and Cambridge in 2021.
Since this is a one to many relationship the most obvious solution would be to create a second table - UserEducation which references userID.
However, I feel a bit wrong about this approach as a user's educational institutions are directly a part of their profile rather than a new set of data. Is there any other way to do this (which somehow keeps the idea of separate entries for each user profile) or is the way I am doing it fine?

I vote for 1:many -- 1 user to many institutions. I vote against many-to-many because of the year being involved.
The 1:many table would look like:
John may have gone to Harvard in 2019, Oxford in 2020 and Cambridge in 2021.
John Harvard 2019
John Oxford 2020
John Cambridge 2021
Leslie Cambridge 2019
"John" would probably be an "id" for JOINing to the Persons table, where you have one row for John and one for Leslie.
You may do likewise for Harvard and a different id -- if you have more information about the schools. (If there is no further info, don't bother.)
If you don't need to search or sort or Join on school, the Ali's suggestion of a JSON column with all the schools for each user, in the Persons table, would work fine.

Related

Count Unique Column Strings and Compare with Another Column

So, I'm new to BO Web Intelligence, so I'll try to explain my problem. I created a simple table below to represent my report. "Tom Smith" is a section break, which is followed by Ann Marie, etc. There is also a break on "Name", which represents clients. Client names are listed more than once since each has multiple "goals" and each goal was touched multiple times (time entered working on goals).
Basically, I want to find all the unique goals for each client in the "Goal" column of the report and see if there is a match in the "GoalTime" column. Goals in the "GoalTime" column are supposed to be the same goals as the "Goal" column, so if there is a goal that doesn't match, or an extra goal, this needs to be flagged and counted to produce totals, percentages, etc.
Is there a way to only display unique values for each client in "Goal"? I know there are ways of playing with the query, universes, filters, etc, to try to create the goal column so that only one goal type is displayed, but I'm looking for a simpler formula-based solution. I'm hoping there is some creative use of a "unique" or "distinct" function, or a creatve way of using "match" to achieve this, which can then be combined with flags to create a count.
Any help would be greatly appreciated!
Tom Smith:
Name: Goal: GoalTime:
Tim Buy a House Buy a House
Tim Find Employment Find Employment
Tim Buy a House Buy a Car
Tim Find Employment Find Employment
Chris Find Employment Find Employment
Chris Buy a House Buy a Car
Chris Buy a Car Buy a House
Chris Buy a Car Buy a Car
Ann Marie:
Name: Goal: GoalTime:
Tom Buy a House Buy a Car
Tom Find Employment Find Employment

How can I create a relational database for a "time-logging" service?

I currently have a database of customers. I would like to be able to query the database and see the list of dates the customer has made an appointment. For example, if I select John Doe, I want to be able to see that he had an appointment on June 6th, July 2nd, and July 24th, etc. and the total cost of the appointment. I feel like I can probably do this using a relational database, but I can't figure out a really good structure. Would a table of dates be a parent to the child customer table?
Thank you!
Thanks to Mihai, I'll create an appointment table that links customers with a datetime value!

How Can I Change One Column With No Patterns to Clearly Defined Rows and Columns?

Looking for any tricks using SQL or Excel to clean up a ~100k record table that has no clear pattern. The data generally looks like this all blocked together in separate rows but the same column:
JENNIFER SMITH
Accountant - Senior
Day Shift
jsmith#mail.com
AMBER Jones
Professional
Pro Status
amberj#mail.com
Abby Stone
Receptionist
Analytics
123 Main St
123-456-7890
abby#mail.com
REBECCA MILLER
Media
Building 2
millerr#mail.com
Sarah M Myers
Executive
BRADBURY SCHOOL
456 Main St
The big problem is that some records have three sets of additional data beneath it and some records have five -- maybe they have an email and/or phone number maybe they don't, some have lines after the record some don't, etc.
I'm looking for ideas either using code or formulas to attempt to clean this up to look like below without going through every line manually:
Name Job Info Email Phone Address
JENNIFER SMITH Accountant - Senior Day Shift jsmith#mail.com
AMBER Jones Professional Pro Status amberj#mail.com
Abby Stone Receptionist Analytics abby#mail.com 123-456-7890 123 Main St
REBECCA MILLER Media Building 2 millerr#mail.com
Sarah M Myers Executive BRADBURY SCHOOL 456 Main St
Hoping people might have ideas using scenarios they've had to use in the past on really messy datasets that come in like this. If it's in Excel, it could be some combination of using SEARCH() or LEN() to try and identify when each record's data is over.
I know it's not the most pointed question -- but if anybody has any tips it'd really help me out. It also doesn't have to end up being perfect -- if it ends up looking mildly like above, I'll be able to clean it manually from that point on, just not from the start.
Any help using any method would be greatly appreciated!
You would spend more time jerking around with this with code than it would be worth. Such badly formatted data can't possibly be accurate. How on earth would you know Jennifer Smith still uses the email address indicated or has the job listed? If you are somehow forced to work on this data then you would be better off paying a human to key it in. That shouldn't take more than a week and you can probably get someone to do it for a few hundred bucks. Even so, that data is certainly crap so I can't see the point in bothering.

Database Design - Storing Requirements

Suppose we want to store university courses and their entry requirements in a database. So for example BSc Mathematics, BSc Fine Art, MSc Computer Science etc.
Each course has it's own set of requirements, and might have a different number of non-shared requirements. For example, to be eligible for the BSc Maths you might need a A in Maths and a B in Physics. Whereas the BSc Fine Art might require a A in Art and that the user has a portfolio. The MSc might have a minimum age of 25 etc.
Suppose we then have a student who has his own set of attributes. So they might have a A in Maths and a B in Physics and a C in Chemistry and be of age 19.
How can we structure our database such that it is geared towards efficient lookups. And given a student's attributes how can we retrieve all the courses which they are eligible for?
On an abstract level we are looking for all items whose requirements are a subset of the attributes given.
I'd like to implement this in MySQL. The schema could be:
courses
id
name
requirements
course_id
subject
grade
But then how to do query the table to get all eligible courses when the student has a A in Subject 1, a B in Subject 2 etc.
For a course to be a match, each one of its requirements must be satisfied.
Thanks in advance, I hope my explanation isn't too confusing.
Okay. I think you need a subject list, with a bunch of subject id's.
Now, for the query, you will start with (or generate) a bunch of subject id's and grades. The easiest thing to do is to make this into a temporary table with those columns.
Now, you can do your query, joining the subject id's, and adding a "where temp.grade <= course.grade.
The trick to this is to count the rows. If it has the same number of rows as the course has specified, then you have a successful match.
Is that enough to get you going?

Acess 2007 one-to-many relationship counting

My Set-up: I have two tables: tblAuthors and tblBooks. tblAuthors includes a list authors: Kurt Vonnegut, Frank Herbert, J. K. Rowling, John Nichols, etc.. tblBooks includes a list of books: Slaughter House Five, Cat's Craddle, Monkey House, Dune, Harry Potter, Milagro Beanfield War, etc..
There is a one-to-many relationship between tblBooks and tblAuthors; Authors in tblAuthors is used as the primary key for this relationship. tblAuthors has a Number of Books coloumn which tells the user of the table how many books each author has written that is included in the table. Currently the user (sadly me) must input this information by hand, updating it after every book is entered and given an author. Although this is not particularly difficult because I can simply see how many books are related to the author in tblAuthors because of the relationship, it is sometimes difficult to remember to update it (not to mention a colossal pain in the butt).
I want Number of Books to update automatically as I add more books. If there is a code out there please let me know!!
I am not really familiar with VBA and could use an explanation that is geared towards someone who may not understand all of the facets of the code.
Thank you in advance for any help that you give me!
You might like to read about relational database design It is not usual to store calculated fields because the information can easily be obtained from a query.
SELECT AuthorID,
Count(BookID)
FROM Books
GROUP BY AuthorID