How to answer OData sample questions - odata

The below question is based in OData.
The service root - https:IIODataDemo:80801MyService.svc
Customerlnvoices and Customers are two entity sets based on the CustomerInvoice and Customer entity types.
It is a big help if anyone can provide answers to the questions below.
Retrieve Customer No and Billing Address of the Customer Invoice where InvoiceId is 15104.
Retrieve all the Customer Invoices ordered by Invoiceld (Ascending) and CustomerNo(Descending).
Retrieve all Customers placed between 50th and 1ooth positions when ordered by Customer No in ascending order.
Thanks in advance.

serviceroot/CustomerInvoice('15104')?$select=CustomerNo,BillingAddress
serviceroot/CustomerInvoice?$orderby=InvoiceId asc, CustomerNo desc
serviceroot/CustomerInvoice?#skip=49&$top=50&CustomerNo asc

Related

Two fact tables with same hierachy but different granularity

Suppose the following hypothetical situation where we need two Fact tables defined as:
Evaluation fact table
UserID
SchoolID
CourseID
Status (passed/not passed)
UserResponse Fact table
UserID
SchoolID
CourseID
SubjectID
SurveyID
Response
It's clear that we need a User dimension table, but how would be modelling the another hiercarhy dimension?
The two possible approaches that we have are:
1 - Model all the dimensions separately and relate them to each other (snowflake schema) and relate de fact table to the corresponding dimension. In this case we need multiple joins when build a query.
2 - Following the kimball recommendation, we should unify all 1:n relations in a unique dimension but with this aproximation we should build two dimensions that contain same information but with different granularity:
dim Survey
ID
SurveyDescription
SubjectID
SubjectDescription
CourseID
CourseDescription
SubjectID
SubjectDescription
SchoolID
SchoolDescription
dimCourse
ID
CourseDescription
SubjectID
SubjectDescription
SchoolID
SchoolDescription
Which approach is more appropiate?
Why don't you create your data model like this:
If you have specific questions about how to populate each table, provide sample data, we might help.
Update: According to your question below, you can find answers like these with this model, assuming user is same as student
(added schoolName to dim_school table)
This query below will give you the answer for how many students there are in a school based on the data you have in your fact_evaluation table.
If you ask in general how many students there are in a particular school you need more info like enrollments etc.
select schoolName, count(distinct userID)
from fact_evaluation f
join dim_school d on d.schoolID = f.schoolID
where schoolName = <a school name>
group by 1

How to store data in fact table with multiple products in an order in data warehouse

I am trying to design a dimensional modeling for data warehousing for one of my project(Sales Order). I'm new to this concept.
So far, I could understand that the product, customer and date can be stored in the dimension table and the order info will be in the fact table.
Date_dimension table structure will be
date_dim_id, date, week_number, month_number
Product_dimension table structure will be
product_dim_id, product_name, desc, sku
Order_fact table structure will be
order_id, product_dim_id(fk), date_dim_id(fk), order_quantity, order_total_price, etc
If a order is place with 2 or more number of product, will there be repeated entry in the order_fact table for the same order_id, date_dim_id
Please help on this. I'm confused here. I know that in a relational database, order table will have one entry per order and relation between the product and order will be maintained in a different table having the order_id and product_id as the foreign key.
Thanks in advance.
This is a classic case where you should (probbaly) have two fact tables
FactOrderHeader and FactOrderDetail.
FactOrderHeader will have a record for each order, storing information regarding the value of the order and any order level discounts; though they could be expressed as an OrderDetail record in some cases.
FactOrderDetail will have a record for each order line, storing information regard the product, product cost, product sale price, number of items, item discount. etc.
You may need to have a DimOrderHeader as well, if there are non-Fact pieces of information that you want to store, for example, date the order was taken, delivered, paid.

How to move between several tables without using joins

I need to "Display all the columns of Employee for those employees who invoiced a vehicle that was owned by a dealership that is different than the dealership that the employee works for."
I'm not allowed to use joins to answer this question so I'm a little confused as to how to get all the information from these tables. I'd need to see if an employee invoiced a vehicle, then determine which dealership that vehicle is sold at, then determine if that dealerships id code is the same as the employees id code.
What are some possible alternatives to using join.
Invoice, Employee, Dealership, and Vehicle are each their own table.
Nested statements are a possible alternative.
select * from Employees e
where employeeID is in
(select ieid from Invoice
where ivin is in
(select vehicleID from Vehicle
where vdcode <> e.edcode))

How to rank records using values from another model?

I am new to rails.
Have this problem. I have two models customers and orders. customer has_many orders, and orders belongs_to customer. Each order has a money value: cost.
Now how can i rank the customers by the total cost spent on all of his/her orders ?
Thank you very much for any help!
you can do something like below
Customer.joins(:orders).select('customers.id, sum(orders.cost) as total_order_cost').order("total_order_cost")
use order("total_order_cost desc") if you want it in descending order
You need to use grouping to total the orders for each customer. You can then order by the totals.
http://guides.rubyonrails.org/active_record_querying.html#group has an example that is similar to what you are doing.

Neo4j - Searching from an array of nodes

In my situation I've a bunch of nodes that represent the users
and they have relation to books they read.
This user have a property that says where they are from, and I added them to an index, based on their country.
So I would like to search in the index for users from one country, and list the books that people from there read more, some sorting by grouping.
could any one give me a help how to do this?
I'm having some trouble getting users from the index, and doing the query
Couple of assumptions based on your descriptions:
users have a country property, it contains e.g. France as value
you have a index called users and you store the user node's country property there
relationship type to connect users and books is READ
book nodes have a title property
Based on these assumptions the cypher query would look like:
start user=node:users(country='France')
match user-[:READ]->book
return book.title, count(*) as rank
order by rank desc
limit 20
side note: best approach to ask this kind of questions is to create a sample graph on http://console.neo4j.org and share your setup on SO.

Resources