outputing JSON data into SQL table format - sql

link for the database and the JSON file:
https://www.transfernow.net/en/dltransfer?utm_source=20220406hCbu1XIk
download incoming_students.json and iroonwood database from the link above and review the data. We will use these files to dynamically add new students to the Ironwood database.
There are some challenges in this part of the lab to consider:
• You are given the advisor's name in this file, and you will have to derive the ID value (which can be looked up as the instructor ID in the instructor table)
• The same process will need to be followed for looking up the state abbreviation for the provided state name
• The address object will need to be parsed
• The user ID is derived as follows: lastNameFirstInit + number of occurrences in the database. For example, there is Clifford Wall in the database. His userID is wallc1 because there is only one wallc userid. But there is an incoming student in the JSON file that is Candy Wall, so her ID should dynamically come out to wallc2
• A successful import of the JSON file should result in the following student table:
enter image description here
i created 2 seperate tables, one for the Address info, and one for the Student Info,
and i like to know, how can i do the above challenges, so that i can dynamically add the new students into the student table?

Related

Write SQL code in BigQuery to get the data in format attribute1:attribute_value1;attribute2:attribute_value2

I am working on the first party data. Each line in the data file for first-party data must contain all the data for a given user and should be delimited using the CARET (^) character.
The file needs to be UTF-8 encoding (or us-ascii)
Each line in the data file should contain 2 columns:
The first column represents the first-party User ID and must match the client first-party User ID that is used in the user matching process described in section 2
The second column contains all the data associated with the user and should be in the following format:
attribute1:attribute_value1;attribute2:attribute_value2
For example, if there are 3 columns called Age Group, Gender, and Interest in the client’s registration database that need to be imported into Audience Studio, then the following represents a valid data file that can be ingested by Audience Studio:
User1234^gender:male;age:18-24;interest:fishing
User2345^gender:female
I have uploaded the csv file in the table in the bigQuery, But i am not able to perform the column formatting using SQL. Can someone please help?
The first step is to split your columns into user_id and attributes columns which can simply be done with the split function. Then you have a few options, here is the simplest one maybe:
SELECT
user_id,
REGEXP_EXTRACT(attributes, "gender:(.*?)(?:;|$)") AS gender,
REGEXP_EXTRACT(attributes, "age:(.*?)(?:;|$)") AS age,
REGEXP_EXTRACT(attributes, "interest:(.*?)(?:;|$)") AS interest,
FROM (
SELECT
SPLIT(rawline, "^")[OFFSET(0)] AS user_id,
SPLIT(rawline, "^")[OFFSET(1)] AS attributes,
FROM
`yourdataset.yourtable`
)
You can also take inspiration from that answer by #Mikhail_Berlyant.

SQL Server nested table

Persons: theoretically, unlimited number of persons can be registered in the system. Contact information linked to each person should also be able to be added without limits.
UUID
Name
Surname
Company
Communication information:
Information Type: Telephone Number, E-mail Address, Location
Information Content
Report:
Location information
Most -> Least to be listed by their number of locations
The number of people registered in the directory at that location
Number of phone numbers registered in the phone book at that location
I have 2 tables, how should the relationship be between them and I am confused since the Communication information attribute has 2 attributes in itself. Should communication information be in a separate table?
I would suggest to divide this into three tables:
Persons(UUID,Name,Surname,Company)
CommunicationType(Telephone Number, E-mail Address,)
CommunicationInformation(Person_ID,CommunicationType_ID, ......)

Check if a pair of values is already used and dont allow entering differenet pair that shares one of the values with already used pair

I have MS ACCESS 2010 database that I made for some of my co-workers. The purpose of the database is to gather manual information in more automated way about some employees (instead of emailing files or having to rely on buggy excel sharing features).
I managed to make sure that each user see only their own data using query as a mean of interfacing with user and checking windows api to get user name.
Now I have a specific problem that I don't know how to solve:
Table contains of 3 columns that user have to enter manually:
ID
Name
Location
ID is not ID of this table, its an ID from totally different system that I can not interface with so it have to be manually entered along with name as I need it later. ID is unique for each employee.
Now I made sure that user can not enter unique combination of those three columns twice using constrains (the same name/id can be used for different locations), but what is possible is that user enter the same ID with different name (not good), or the same name with different ID (possible as employees may have the same name).
Is there a way to check upon entering of data if a given ID exists with different name then the one entered by the user?
Example:
ID NAME LOCATION
123 Martin Warszawa - OK
123 Martin Kraków - OK (the same person assigned to his second location)
124 Martin Kraków - OK (same name as another guy from Kraków, but two different persons)
123 Paul Wrocław - NOT OK (ID points to Martin, so it should not be entered as Paul)
123 Martin Warszawa - NOT OK (duplicated first row - blocked with constrains)
Can this even be accomplished?
What I would want to retain is the ability to enter values by users in the query window and this as far as I know will be compromised if I change this into One:Many table relationship.
I assume that macro/sql procedure could be used to accomplish that and block insert attempt but I don't know how to accomplish it
Normalize your database. You have users identified by an ID (primary key bold):
users (id, name)
and their locations:
user_locations (user_id, location)
So there can be no longer be duplicate user entries and there can be no duplicate locations. If you want to add something, use INSERT. If that fails, it means the entry is already there. If you want to update something, use UPDATE. If you want to insert or update depending, try INSERT first; if this fails UPDATE. (You can search for upsert and MS-Access, and you will find how this is done).

what editable control should i use to display my spreadsheet in a vb.net application?

I have a spreadsheet in excel with three headers:
Project Name
The name of a project i'm working on.
Requested Role
The job title/profession of the project employee. (example: mechanic, manager, engineer)
Name
The name of the employee.
When i click on the Person's name i want another page or tab (specific to this person) to appear showing details about them such as their name, job title, how long they worked, what project they are doing... etc. (similar to a Facebook profile)
When i click on the project name i want another page or tab (specific to this project) to appear showing details about it such as the requirements, the deadline, who is currently working on it... etc.
Furthermore, i would like to set up two levels of access:
Managers:
People who can add new information but not change or delete existing information
(write-only permissions)
Administrators:
People who can have full access to all information.
All highest level of access.
I don't know how i would go about displaying and/or organizing so much information in a vb.net application. if anyone could provide some suggestions as to some possible layouts of the GUI it would be greatly appreciated!
Additional Details:
For the specific pages i was thinking of using the tab control but i want it so that i can search through the list of projects or names, select one, and then it brings up the page about it.
The levels of access is the least of my worries... although it is still a worry.
You don't want to store that information in an excel spreadsheet, a database is much, much better. For what you've described here I'm going to assume that you have Projects and Employees, and that multiple Employees can work on a project. You'll need a few tables then:
Project
ProjectSeq 'Int - unique sequence for this project record
Name 'String - name of project
Descr 'String - description of project
... 'Various - other fields as needed
Employee
EmployeeSeq 'Int - unique sequence for this employee record
Name 'String - Name of employee
Title 'String - Job title of this employee
IsManager 'Boolean - Is this employee a manager?
IsAdmin 'Boolean - Is this employee an administrator?
... 'Various - other fields as needed
ProjEmpl
ProjEmplSeq 'Int - unique sequence for this project-employee record
ProjSeq 'Int - link to project record
EmployeeSeq 'Int - link to employee record
... 'Various - other fields that apply to this project-employee combination
Once you have your tables all set up and populated with data, you'll want to read the data and transfer it to your .NET application. There are a few ways of doing this, you'll have to decide which works best for your needs. I'm a big fan of DataSets, they always work nicely.
To fill the grid, you'll need to use a sql statement that fills a datatable from the three tables (I'm using notepad as my IDE, so this may not be exact):
SELECT pe.*, p.Name as ProjName, e.Name as EmplName, e.Title
FROM ProjEmpl pe, Project p, Employee e
WHERE p.ProjectSeq = pe.ProjectSeq AND
e.EmployeeSeq = pe.EmployeeSeq
To display the data to the end user, you would use a DataGridView control. Set the datagrid.DataSource to use the datatable you just populated and the data should show up.
To display the related Employee & Project information, I'd use a tab control underneath the datagrid. One tab for Project, and one tab for Employee. Use individual controls for each field in the table. When the user changes rows in the datagrid, load the related Project and Employee information for that row into two datatables and populate the controls from that.
Lastly, to set permissions on the program you'll need to have the employee log onto the application. Once they've logged on you can look them up in the Employee table, find out if they are a manager or an administrator, and set the permissions accordingly.

MySQL joins for friend feed

I'm currently logging all actions of users and want to display their actions for the people following them to see - kind of like Facebook does it for friends.
I'm logging all these actions in a table with the following structure:
id - PK
userid - id of the user whose action gets logged
actiondate - when the action happened
actiontypeid - id of the type of action (actiontypes stored in a different table - i.e. following other users, writing on people's profiles, creating new content, commenting on existing content, etc.)
objectid - id of the object they just created (i.e. comment id)
onobjectid - id of the object they did the action to (i.e. id of the content that they commented on)
Now the problem is there are several types of actions that get logged (actiontypeid).
What would be the best way of retrieving the data to display to the user?
The easiest way out would be gabbing the people the user follows dataset and then just go from there and grab all other info from the other tables (i.e. the names of the users the people you're following just started following, names of the user profiles they wrote on, etc.). This however would create a a huge amount of small queries and trips to the database in a while loop. Not a good idea.
I could use joins to retrieve everything in one massive data set, but how would I know where to grab the data from in just one query? - there's different types of actions that require me to look into several different tables to retrieve data, based on the actiontypeid...
i.e. To get User X is now following User Y I'd have to get my data (User Y's username) from the followers table, whereas User X commented on content Y would need me to look in the content table to get the content's title and URL.
Any tips are welcome, thanks!
Consider creating several views for different actiontypeids. Union them to have one full history.