I've got a database to be developed for a MLM (Multi Level Marketing) company. So, there's one customers table, each customer has a unique ID called CustomerId, and all customers can have customers under them can make N customers down to 1 customer.
All customers are added to the same table tblCustomer and for each customer there's a another table tblCustomerUplink where I add customer's customerId under whom that customer is.
tblCustomerUplink structure is look like below:
Our system have a fixed 5 level where check customer's level based on refer count and allocate level accordingly.
Suppose:
Level ReferLimit Commission
Level1 5 5
Level2 10 3
Level3 15 2
I have this table (Day, Employee no, Employee Name, Client no, Client name, Product no, Product Description, Unit Price, Quantity Sold, Total Sales)
Example data :
22nd, e123, Dave, c1264, Sheila, p15462, Hoover, 4.50, 5, --
----, ----, -----, c64402, Jovek, p673431, Kettle, 2.25, 10, 45
----, e4215, Johnny, c785, Keith, p15462, Hoober, 4.50, 2, 9
23rd, e123, Dave, c64402, Jovek, p673431, Kettle, 2.25, 20, --
So basically, there is only data for the day if its a new day entry, and there is only a total for total sales, after all the sales that an employee has made.
So far, I have got :
Product(ProdNo#,ProductDesc,Price)
Client(ClientNo#, ClientName)
Employee(EmployeeNo#, EmployeeName)
However, I'm unsure what to do regarding the individual sales and total sales for every day?
Thanks for any help!
This is typical example for the use of a star- or snowflake schema.
The tables Product, Customer, Employee are called dimension tables.
The fact table has foreign keys to the dimension table and contains a quantity, e.g. the concrete sale.
Sales(ProdNo#, ClientNo#, EmployeeNo#, Sale)
The primary key of is a compound key of ProdNo#, ClientNo#, EmployeeNo#.
Total sales would not be modelled explicitly but queried via aggregation, e.g.
SELECT P.ProdNo, SUM(S.sale)
FROM Products P, Sales S
WHERE P.Price > 1000 AND S.ProdNo = P.ProdNo
GROUP BY P.ProdNo
The RDBMS or data warehouse will optimize the query, so total sales do need to be modeled explicitly (no denormalization).
I'm trying to model a simple address book schema that I will use for HBase/Cassandra.
The scenario:
A user can create his contacts.
A contact may have many phones, addresses or emails.
A user can create groups to organize his contacts (a group can contain many contacts and a contact can be placed in many groups).
The only select query that I'm planning to do is to grab all the contacts who live at address x and are in group y.
Would the following schema be appropriate for this?
|Table name: User |
-----------------------
Key: user_id
email
password
-----------------------
Column family: Contacts
Key: contact_id
firstname
lastname
---------------
Column family: Address
Key: address_id
street
housenumber
zipcode
---------------
Column family: Group
groupname
Or is this better/possible?
|Table name: User |
-----------------------
Key: user_id
email
password
-----------------------
Column family: Contacts
Key: contact_id
firstname
lastname
contact_id
|Table name: Address |
-----------------------
Key: address_id
street
housenumber
zipcode
contact_id
|Table name: Group |
-----------------------
Key: group_id
group_name
Addresses tend to get more complicated and you could add addtional, denormalized column families/tables to support your queries.
EDIT: Since you're more concerned with querying on Address and Group, you should add two new, denormalized tables: one keyed by address_id and one by group_id.
I can't speak to HBase solutions for this problem, but in Cassandra 2.1+, there is support for User Defined Types. The documentation from that link has a good example of modeling the user-address entity relationship.
I am currently creating an Android application which should use SQLite database. In my case, I need to strore "product type", "bill" and "list of all purchased products"
Bill:
id
customer
data -> link to list of all purchased products
price
Product types:
id
name
price
My question is: One customer could have more products connected to one bill. How to design it? Is using a Use a one row for every bills:
id
bill_id
product
or rather insert more products into one row and then parse it in my application? I suppose, there is a better solution that these mine. Thank you for help.
You said in your question, "One customer could have more products connected to one bill."
Another way of saying this is, one customer can have 0 or more bills, and one bill can have 1 or more products.
After rephrasing your statement, the database normalization becomes more obvious.
Customer
--------
Customer ID
Customer Name
...
Bill
----
Bill ID
Customer ID
Bill Time Stamp
Bill-Product
------------
Bill ID
Product ID
Product
-------
Product ID
Product Name
Product Price
...
To design customer order with bill we can design it as below:
This schema having basics attributes we can add more as per requirements.
Customers Table
id PK
full_name
address
phone
MenuItems Table
id PK
item_name
item_description
item_price
Order Table
id PK
customer_id FK
order_date
OrderDetails Table
id PK
order_id FK
menu_item_id fk
quantity
Bill Table
id PK
order_id FK
amount
bill_date
I have a couple thousand franchises, and about 3 or 4 service groups. The service groups are in a separate table, then i have third table joining them together. A franchise may be connected to 1 or many service groups. What I am trying to achieve is listing out the franchises, with a column labeled "Service Categories". It would then be a comma separated list of which services they provide. So right now, here's my output:
id Service Groups name email address City State
1 Cleaning Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
2 Disaster Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
I would like to have it so it becomes this:
id Service Groups name email address City State
1 Cleaning Services, Disaster Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
Any suggestions or references of methods/functions I can use to do this would be greately appreciated. Thanks!
try this
Declare #TempServiceGroups varchar(max)=''
Select COALESCE(#TempServiceGroups,'')+ServiceGroups+',' from MyTable
Select #TempServiceGroups AS ServiceGroups , Name,Email,Address,City,State
from MyTable