Add categorical type where no data exists - bar-chart

I have a number (11) questions which generate the following categorical data answers:
Poor,
Fair,
Satisfactory,
Very good,
Excellent
from a 5 point answer set.
I wish to create bar plots where that all have the same categories reflected even when there is no data.
Of the 5 categories, some of the data has 3, some 4 and some all 5 ratings, but in order to make the plots look similar I want each plot to have all 5.
I can create the bar plots and re-order the data, since I want them all in a specific order.
What I can't seem to find a solution for is to add categories where there is no data.
eg I have "Excellent", "Very good" and "Satisfactory" and I want to add "Fair" and Poor"
Any help on a solution would be extremely useful.
Thanks in advance
Regards
Steve

Related

Mysql table structure design for economic data

Dear all Mysql experts
I am very new for Mysql, please providing me some guides here. I have data as shown in picture above, and I am trying to design table structure of Mysql to store those data and the data will be added over the years, which i dont want to record same indicator multiple times. at the moment i was thinking about split the data into 3 tables: indicator table to hole indicator name, data value table to hold data value and year and the geography table to hold provinces but i am not quite sure if that approach is right please giving me some shade of light. Thank you very much.
Because its a simple question that deserves a simple answer, here is a suggestion. As per the comments, the sample data you have given is ambiguous, but with assumptions this is it.
From your data, it looks like Indicator, Category and Source are all attributes of the same entity. It also looks like there are an arbitrary number of provinces. If so then you are likely to have three tables
Indicator(IndicatorID,IndicatorText,Category,Source)
Province(ProvinceID,ProvinceName)
YearValue(IndicatorID,ProvinceID,Year,Value)
You would probably not store the national value, just add up the provinces.

Access relationship looping example

I am struggling with some basics of MS Access 2010/2013. I am not sure if I did hit the limit of it or if I am just using the wrong procedure. I will explain what i need.
Take for example 5 items in a shop, where 3 are items and 2 are a combination of items.
They need to be presented in the same matter, i.e. the combinations of products (bundles), needs to have a number in the same series as those it contains. See figure below:
So far, I created 2 tables. 1 for stand alone products and 1 for bundles. Bundles should be able to include other bundles (This is where i get the problems).
If someone orders, lets say, 10 times Items 5, I need Access to count how many Motherboards (Item 1), how many CPU (item 2) etc. I need a full list of those items, so i hopefully should get a list that says:
10 x Motherboard
10 x CPU
10 x Cabinet
So i don't have to dig into each bundle. Hence, as i see it, the relationsship runs in sort of a loop.
I identify the items to be either a combination or product by a column with "yes/no".
If you have any suggestions, let me know, or if you think i hit the limit.
An alternative method is welcome, as well as a sample of a simple Access database.
For the record, the system is gonna be used for huge machines, creating lists of bolts, nuts, electrical equipment etc. The above is only to explain my thoughts.
Best Regards, Emil.

Best way to store trivia alternatives?

I'm creating an application that asks the user a question and demands an answer in the form of a country.
For example: Where is the Eifell Tower located?
The user is presented with a number of alternatives, lets say 10 different countries.
The problem arrises when I want to store every answer to a mySQL-database. I have a table with all the countries, and need to store which of them were included in the question. However, doing it this way would create, in this case, 10 database rows for a single answered question. I've been looking into storing the included countries as a bit mask, but a single bit mask wouldn't be enough with over 150 possible countries.
Any help on what would be a good way to store the data is much appreciated!
Thanks!
I'd just store The relation in a table like you are suggesting. I.e, three tables where the first contains questions (Id, question_text, ..), the second table contains all the countries (Id, name, ..) and the third table contains the relation that says what country is an option in which question (question_id, country_id). Like you say this gives ten rows in the relationship table for a single question, but are you really facing a storage space or performance problem here?
If you have 10k such questions, it is still just 100k rows and less than a megabyte of data. The questions themselves will have a lot more data than that, so the relation between question and country shouldn't be an issue as far as I can see.

Any way to compare/match sentences with only a different word order?

I have 2 MySQL tables , each with address data of companies in it. One table is more recent, but has no telephone and no website data. Now I want to unite these tables into 1 recent and complete table.
But for some companies the order of the words is different,like this:
'Bakery Johnson' in table 1 and 'Johnson Bakery' in table 2.
Now I need to find a way to compare these values, as they're obviously the same company.
I think I will somehow have to split those names first, and then order the different parts alphabetically.
Any chance anybody has done something like this before, and willing to share some code or function?
UPDATE:
I found a function that sorts words inside a string. I can use this to detect name swaps as described above. It's quite SLOW though...
See : MySQL: how to sort the words in a string using a stored function?
If your table is MyISAM you can run this query:
SELECT *
FROM mytable
WHERE MATCH(name) AGAINST ('+bakery +johnson')
This will find all records containing the words bakery and johnson (and probably some other words too).
Creating a FULLTEXT index on the table:
CREATE FULLTEXT INDEX
fx_mytable_name
ON mytable (name)
will speed up this query.
Going back a bit on your solution, you could go with a similar way as modern phones resolve duplicate names conflicts
You present your user with the option, as he finds something suspicious:
Is this a duplicate? Use our [ Merge ] option
You are merging Bakery Johnson, please select the source/original item:
[ Johnson Bakery v ] (my amazing dropdown!)
Everything not already in Johnson Bakery gets ported to Bakery Johnson (orders for example), you may also show an intermediate screen displaying what will be merged, or let the user pick, for example, he wants the address info from Johnson Bakery and orders from both etc
It is not self correcting as you asked, but the collaboration from the users may be more accurate than AI here. I also love low-tech solutions like this so let us know what you ended up doing.

MYSQL: How can I store/retrieve a value based on the 3+ other values in the same table?

Let's say I'm making a program for an English class. I'd like to store data in this way:
ID Object
0 Present Tense
1 1st person singular
2 To Be
3 I am
How can I retrieve the value for ID 3 based on IDs 0-2? The only thing I can think of is:
ID Object FromIDs
3 I am 0,1,2
The problem with this is that I'd have to do a fulltext index and I think this table is going to get pretty large. I don't want separate tables for different types of objects, if possible, because I don't know what I'll end up doing with these objects and I want as much flexibility as possible. I could have a second table relating IDs to each other, but I've only done that successfully relating a column from one table to a column to another.
Thanks in advance!
You need to break the data into different tables. Have a table that stores the "tense"
and another that stores the type "1st person singular".
Can you explain your problem a little more. From what you have I'm not sure if you're trying to go down the path of Entity-Attribute-Value or probably what is more likely is that relational database is not a good fit for your problem; you may need to use some sort of tree data structure. If you update, I can try to provide a better answer.
What I've decided to do is a combination of what was suggested and what I originally thought. I'm going to have a master list with IDs that are auto-incremented and copied to other tables. That way, I have properties of different parts of speech separated, but still have everything relating to everything else.
This is really not a good fit for a relational database. Sorry, you're trying to drive a nail using a screwdriver.
When you have no distinction between an attribute type and a value, you're modeling semantic data. The open standard for this type of data modeling is RDF.
My solution (if you really dont want to break up the table)
**ParentChildTable**
ParentID ChildID
0 3
1 3
2 3
But well, in one table now you have:
-type of tense
-type of person (1st, 3rd....)
-values
So i think it would be better to split, i can see .. .well, right now, 3 tables: values, tensetypes, personetypes and relationship table (value-value for tense/person)