Database
Author
Discussion

stevenjhepburn

Original Poster:

291 posts

160 months

Saturday 10th August 2013
quotequote all
With little prior experience, how easy would it be to create a database with the following specification:

Inputs as a list. For example:

Item 1
Item 2
Item 3
Item ...
Item n

Then sorted/queried to show which items come before/after each individual item.

A basic example:

John has Cereal, Toast and Tea for breakfast.
James has Toast, Milk and Banana for breakfast.
Jack has Tea, Porage and Yoghurt for breakfast.

I would like to put these into a database as [item 1], [item 2] and [item 3] the ask the database "What did anyone have after eating toast" with the answer being " 1 Tea, 1 Milk".

davepoth

29,395 posts

230 months

Saturday 10th August 2013
quotequote all
Being lazy, I would probably do it using the SUMIFS function in Excel.

stevenjhepburn

Original Poster:

291 posts

160 months

Saturday 10th August 2013
quotequote all
davepoth said:
Being lazy, I would probably do it using the SUMIFS function in Excel.
Would that work with the items being in different columns? In the breakfast example John's toast might be in column C whilst James' toast would be in column B.

JimmyTheHand

1,001 posts

173 months

Saturday 10th August 2013
quotequote all
creating tables, inserting data and returning data in order will be found very early in any good introduction book/tutorial on SQL database. Using tools like MySql Workbench (assuming you are using MySql ) can make them trivial exercises

Understanding what tables and columns the database should contain - is harder (3 tables wouldn't be unreasonable for problem - one for the people, one for food items and one to link the person to the items consumed at meal, though maybe overkill for trivial example)

"What did anyone have after eating toast" - I suspect a lot of programmers would resort to doing in code, though it is possible to construct queries to do it (but likely database dependant)

crazy about cars

4,454 posts

200 months

Saturday 10th August 2013
quotequote all
I think everyone is over thinking here wink

First of all, do you really need a database OP? Tell us more about your requirements - more importantly the scale of it.

If you want an analysis of what people have for breakfast (as an example) you could start with Excel.

Assuming breakfast consists of 3 courses

Column 1 = Name
Column 2 = First item
Column 3 = Second item
Column 4 = Third item

You can create lookup table in Excel (rule validation) so you get nice dropdown in columns 2-4

If you really need a database I'd suggest MS Access. Really easy to start.


xRIEx

8,180 posts

179 months

Saturday 10th August 2013
quotequote all
stevenjhepburn said:
davepoth said:
Being lazy, I would probably do it using the SUMIFS function in Excel.
Would that work with the items being in different columns? In the breakfast example John's toast might be in column C whilst James' toast would be in column B.
Yes, you could do IF statements to test and return the required value. For example, person's name in column A, breakfast items in columns B, C and D and this formula in column E:

 =IF(B2="Toast",C2,IF(C2="Toast",D2,IF(D2="Toast","Toast was the last thing this person had",""))) 


Then COUNTIF the results in column E.

stevenjhepburn

Original Poster:

291 posts

160 months

Saturday 10th August 2013
quotequote all
crazy about cars said:
First of all, do you really need a database OP? Tell us more about your requirements - more importantly the scale of it.
For the idea I have it really has to scale big, quickly.

crazy about cars said:
If you want an analysis of what people have for breakfast (as an example) you could start with Excel.

Assuming breakfast consists of 3 courses

Column 1 = Name
Column 2 = First item
Column 3 = Second item
Column 4 = Third item

You can create lookup table in Excel (rule validation) so you get nice dropdown in columns 2-4
I was a little too uniform in my initial example. For what I'm thinking, the breakfast example equivalent would be some people having 2 items and some people having 10+ items.

davepoth

29,395 posts

230 months

Saturday 10th August 2013
quotequote all
Is the order in which people are eating critical? That makes it a bit tricky.


The Moose

23,710 posts

240 months

Sunday 11th August 2013
quotequote all
Not really difficult if order is required

2 tables, 1 for people, 1 for items

People table - I don't know what info needs storing but say first name, last name, phone number with userid as primary key.

Items table - again, personid, item name and position (I.E. 1 is first, 2 is second etc)

Should be fairly simple with a nice little SQL statement and could handle 2 courses or 2,000,000 courses (mmmmm breakfast with lots of courses!!)

xRIEx

8,180 posts

179 months

Sunday 11th August 2013
quotequote all
stevenjhepburn said:
I was a little too uniform in my initial example. For what I'm thinking, the breakfast example equivalent would be some people having 2 items and some people having 10+ items.
Not a major problem if coding. Off the top of my head, in a pseudo-Excel VBA style:


For Each person In database

MaxItems = Count(HowManyItems)

For NoOfItems = 1 to MaxItems
If Item(NoOfItems) = "Toast" Then
WhatTheyHadAfterToast = Item(NoOfItems + 1)
End If
Next NoOfItems

Next person


'WhatTheyHadAfterToast' would represent an array, an Excel worksheet or a temporary table - whatever would be suitable to store multiple values, then do the COUNTIF or whatever you need to do with it.

stevenjhepburn

Original Poster:

291 posts

160 months

Sunday 11th August 2013
quotequote all
This is obviously way outside my pay-grade and I don't have the time to spend learning databases/advanced excel right now! It will have to remain as a bright idea for the time being.

Thank you everyone for your replies and attempts to help. I appreciate it!

TonyRPH

13,555 posts

199 months

Sunday 11th August 2013
quotequote all
davepoth said:
Is the order in which people are eating critical? That makes it a bit tricky.
Just what I was thinking after reading the OP.

stevenjhepburn said:
<snip>
I would like to put these into a database as [item 1], [item 2] and [item 3] the ask the database "What did anyone have after eating toast" with the answer being " 1 Tea, 1 Milk".
Which I think would mean that you would not only have to record what was eaten, but at what time, or in what sequence.




bishbash

2,447 posts

228 months

Sunday 11th August 2013
quotequote all
TonyRPH said:
Which I think would mean that you would not only have to record what was eaten, but at what time, or in what sequence.
That's not particularly tricky though, either use an auto-increment id (which can't be guaranteed, but I've never seen it fail) or just a timestamp on the what was eaten field?




mikef

6,158 posts

282 months

Sunday 11th August 2013
quotequote all
stevenjhepburn said:
crazy about cars said:
First of all, do you really need a database OP? Tell us more about your requirements - more importantly the scale of it.
For the idea I have it really has to scale big, quickly.
How big? Millions of documents/rows, or billions? If millions and data capture is not real-time, then relational (say mySQL or PostgreSQL for something simple or SQL*Server/Oracle/DB2 for gigabyte to terabyte scale with analytics and reporting)Mwould do the job. For billions of rows, especially with real time data capture, look at Apache Cassandra, Hadoop with Flume or hBase. If text search is an important requirement then combine the above with Apache Lucene or solr.

If you can give more information on the scale and characteristics that you are looking for, you will get better recommendations.

crazy about cars

4,454 posts

200 months

Sunday 11th August 2013
quotequote all
stevenjhepburn said:
I was a little too uniform in my initial example. For what I'm thinking, the breakfast example equivalent would be some people having 2 items and some people having 10+ items.
Still doable but more into database realm (or advanced Excel depending how how you capture the data).