B
B
beduin012015-04-15 11:45:42
MySQL
beduin01, 2015-04-15 11:45:42

MySQL: How rational is this approach to data storage?

Every day the program collects data and puts it in the database. Just two columns: date | data
11/12/2014 | Sky, Air, Water, Stone, Sky, Sky
Next, I need to process and choose the most common words.
Hence two questions:
Does it make sense for me to carry out statistical processing before insertion and glue the words in with the number of repetitions, i.e.
November 12, 2014 | Sky:3, Air:1, Water:1, Stone:1
Next, I need to somehow be able to conveniently request statistics by day. Hence the question. Do I need to convert all words into columns in order to write popularity for each? This is very inconvenient. when there are 5 words, it's ok, but what if I have about 1000 words. What now for each column to create?
How to make it prettier? How to store everything?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid Sysoletin, 2015-04-15
@sysoletin

Well, for example, two tables: "date | id_words | quantity" and "id_words | word".
Which indexes to impose is a topic for independent study.

R
Rsa97, 2015-04-15
@Rsa97

Initially, the data is incorrectly organized. Need one table

CREATE TABLE `table` (
    `date` DATE,
    `word` VARCHAR(64),
    `count` INT, 
    PRIMARY KEY(`date`, `word`));

Adding a word:
INSERT INTO `table` (`date`, `word`, `count`) 
    VALUES (CURDATE(), :word, 1) 
    ON DUPLICATE KEY UPDATE `count` = `count`+1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question