How to check if a value exists in another column of a same table in OBIEE? - case

How do I check if EmpID EE# exists in SupervisorID column and categorize it based on Manager or Individual Contributor in OBIEE.
Here's the table for reference. Currently, consider there are only 2 columns EmpID EE# and SupervisorID. I need a formula to categorize EE's record as "Manager" if EmpID is found in SupervisorID and "Individual Contributor" if EmpID is not found in SupervisorID column.... as shown in column 3.
EmpID EE#
SupervisorID
Manager/Individual Contributor
12140
12138
Manager
11145
12138
Individual Contributor
11149
12140
Individual Contributor
12145
12141
Manager
12150
12142
Individual Contributor
12155
12143
Individual Contributor
12138
12144
Manager
12143
12145
Manager
In Excel I'm using a countif function to verify if the EmpID EE# is found in the SupervisorID field.
i. If the count is greater than zero than we categorize the EE’s record as “Manager”.
ii. If the count is zero then the EE’s is categorized as “Individual Contributor”.

Related

Binding a table to a row?

Lets suppose there are multiple students and I want to bind a student with multiple courses and bind a course with a grade.
For example student "peter" has the course physics with the grade 3, mathematics with the grade 2 and English with the grade 1. Another student "jones" has the courses Spanish with the grade 2 and mathematics with grade 1. And so on...
My approach to this problem would be to create a table for each student with the table name being the students name. These tables would have the columns "course" and "grade". Then I would have a Table called "Students" with the columns "id" and "name". I would have to assign each student id to the right table which contains the courses and marks for that student.
The problem with this approach is, I would have to create a lot of tables. So Is that the proper way to solve this problem in SQLite? How could I bind a table to one student id?
So Is that the proper way to solve this problem in SQLite?
Not really as it then does not conform to normalisation nor does it utilise the power of relationships(binding) i.e. SQLite is a RDBMS/RDMS (Relational DataBase Management System and therefore copes very well with relationships.
How could I bind a table to one student id?
From your descrition you have two major components Students and Courses. Therefore you'd look to creating a table for each.
The students table you would include columns specific to each student and to cater for relationships a column for uniquely identifying each row (see INTEGER PRIMARY KEY below). Rather than a table per student.
So you might have a table with column an id column and a name column (plus other columns as required). e.g. CREATE TABLE (studentid INTEGER PRIMARY KEY, studentname TEXT);
For the courses table you might have a similar table with an id column and a name column. e.g. CREATE TABLE (courseid INTEGER PRIMARY KEY, coursename);.
You would then have a mapping/binding/associative table (many other terms can be used) as from your description there would be a many to many relationship. i.e. A student could be enrolled for a number(many) of cousres; and a course could have a number(many) of students enrolled.
This table would have two columns studentid and cousreid each being a unique combination (assuming that a student wouldn't be enrolled on the same course multiple times).
As you want a grade (I think) per course/student combination, this would be another column (as say could be number of lessons attended/passed and so on).
So you could have a table named enrolments (or whatever name you feel comfortable with) e.g. CREATE TABLE enrolments (courseid INTEGER, studentid INTEGER, grade INTEGER, PRIMARY KEY (courseid, studentid))
A note on INTEGER PRIMARY KEY, this is a special column type it defines the column as an alias for the special (normally unseen) rowid, which will be a unique integer normally 1, then 2 then 3 etc. (Note you will often see INTEGER PRIMARY KEY AUTOINCREMENT, this is similar. However this is rarely needed (it guarantees a higher id but has overheads)) SQLite Autoincrement.
Using the above code results in three tables Students, Cousres and Enrolments
These could be populated, for demonstration purposes, using :-
For the students table :-
INSERT INTO students (studentname) VALUES('Fred');
INSERT INTO students (studentname) VALUES('Bert');
INSERT INTO students (studentname) VALUES('Tom');
Adds 3 students (Fred studentid =1, Bert studentid = 2, Tom studentid = 3)
For the courses table :-
INSERT INTO courses (coursename) VALUES('English');
INSERT INTO courses (coursename) VALUES('Maths');
INSERT INTO courses (coursename) VALUES('Spanish');
Adds 3 courses English courseid=1, Maths courseid=2, Spanish courseid = 3.
For the enrolments table :-
INSERT INTO enrolments VALUES(1,1,0); -- Fred enrolled into English ungraded as yet
INSERT INTO enrolments VALUES(2,3,5); -- Tom enrolled into Maths with grade 5
INSERT INTO enrolments VALUES(2,2,0); -- Bert enrolled into Maths ungraded.
INSERT INTO enrolments VALUES(3,1,0); -- Fred enrolled into Spanish ungraded
INSERT INTO enrolments VALUES(3,2,0); -- Bert enrolled into Spanish ungraded
INSERT INTO enrolments VALUES(3,3,0); -- Tom into Spanish ungraded
Adds 6 enrolments Fred into 2 courses (English and Spanish), Bert into 2 courses (Maths and Spanish) and Tom into 2 courses (Maths and Spanish).
From the courses perspective English has 1 student, Maths has 2 students and Spanish has 3 students.
The tables would look like :-
The following SQL/query shows how you can bind using JOINS :-
SELECT coursename, studentname, grade
FROM enrolments
JOIN students ON enrolments.studentid = students.studentid
JOIN courses ON enrolments.courseid = courses.courseid
ORDER BY coursename, grade DESC;
It could be interpreted as :-
get each row from the enrolments table and additionally get the row from the courses table where the courseid in the courses table matches the courseid in this row of the enrolments table and also additionally get the row from the students table where the studentid in the students table matches the studentid in this row of the enrolments table, sorting the results according to coursename and then by grade (i.e. grade within a course) returning the coursename, studentname and grade columns.
This would result in :-
Say you wanted the number of students per course with the most enrolled in courses first then you could use (student details are irrelevant so the binding is just between the enrolments and the courses tables) :-
SELECT count(), coursename
FROM enrolments JOIN courses ON enrolments.courseid = courses.courseid
GROUP BY coursename
ORDER BY count() DESC;
The result would be :-
The best way to solve this is to create three tables:
The first one is Students table, containing all students info along with student id
The second one is Course table, containing all courses info along with the course id
The last one is the StudentClass (or any better name) table, containing the student id, the course id and the grade for that student

How do I model 1:N:N relationship in Dynamo DB

I have a school which has a many class/grade(1-10) and each class has many students, I need to store a student's record on a yearly basis so that I could partition better. So its basically Class->N years->N students. How do I model this problem to store this on a Dynamo DB
On NoSQL, the design depends on the Query Access Pattern (QAP). As you have not mentioned QAP, how you would like to retreive the data. I have assumed a typical scenario and provided the below design.
Table : Student
Partition Key : Student Id
Sort Key : year
Other attributes: Student name, class etc.
The year is defined as sort key because a student can study in multiple grades (1-10) during different years. For eg,
2010 - He/She could be on grade 5
2011 - He/She could be on grade 6
In case, if you would like to get all the student ids for a particular year, you can create GSI (Global Secondary Index) on year field.
Partition Key for the index : year
If you have any other access pattern, please update the question. So that we can discuss the answer for that particular query access pattern (QAP).

How to maintain tables when we have multiple customers having single product?

What tables and relationships should I design for an app supporting multiple customers?
I am developing a web application which has multiple customers and a single product. I want daily sales data to be stored for each customer - there are about 10 customers.
My application has a screen where the following data is entered and saved:
Customer Name
Price per quantity
Quantity
Total amount
Amount
Balance
Old Balance
Total Balance
I need to decide how to create tables, the number of tables and the relationships between them. For example, should I have separate tables for each customer? I need the total sales to be maintained in database.
You can have two tables. One customer main table with columns Id,Name
Id can be of identity type which increments for every insert of customer name.
CREATE TABLE Customer(
Id INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(30)
)
Second table can be sales table as there is a single product , you can just have that as a column in this table. Columns for this table would be
id(Again identity primary key for sales table)
Product name
Quantity
Total amount
Amount
Balance
Old Balance
Total Balance
CustomerId (foreign key referencing the customer table)
Also sales date can be added to the sales table, which will be helpful to retrieve sales based on date.
While retrieving, you can use the relationship between the tables to get the customer name.
Hope this information helps.

crystal reports count instance by group then sum

My subreport has groupings on Account ID then Invoice No. Within the Account ID I could have several Invoice No's.
For example:
Account 1234
Invoice 6789
Invoice 5432
Invoice 5432
Invoice 9999
What I want is count of invoices. Using the example I should get a count of 3. There are 3 unique invoice numbers under the account id. I have tried a running total, formulas and summary.
Using Distinct Keyword in sql query or linq You Can Solve This Problem.
var data = (from n in tbldemo select n).Distinct();
Now Set data to your crystal report data source. It will helps you.

How is DataAreaId field related to FiscalCalendarPeriod table in Dynamics AX 2012?

I tried many approaches but none of them seems to get me a concrete relation between FiscalCalenderPeriod table and the DataAreaId attribute in dynamics AX 2012.
DataAreaID was a part of LedgerPeriod in Dymanics AX 2009, but now this table has been depriciated, so the data has been normalised.
How can I map FiscalCalenderPeriod with a Company Data i.e. dataareaid?
A DataAreaId identifies a Legal entity (a record in the CompanyInfo table). Each Legal entity has a Ledger (a record in the Ledger table where the PrimaryForLegalEntity field is the RecId of the CompanyInfo record). A Ledger is tied to a FiscalCalendar record by the FiscalCalendar field. FiscalCalendarPeriod records also belong to a particular FiscalCalendar based on the FiscalCalendar field.
There is a helper class FiscalCalendars that has many methods for dealing with Fiscal calendars. For example, here's one way to get the end date of the current period for the company 'CEU':
RecId fiscalCalendarRecId=Ledger::fiscalCalendar(CompanyInfo::find('CEU').RecId);
date currentDate=SystemDateGet();
date endDate=FiscalCalendars::findPeriodEndDateByDate(fiscalCalendarRecId,currentDate);
info(date2StrUsr(endDate));

Resources