Splitting of articles by article ids: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 14: Line 14:
</pre>
</pre>


== Case2: Articles IDs which mix of string and number ==
If the article ID consists of numbers or text, it is divided into two parts after a formula calculation with the remainder equal to 0 or 1, resulting in two parts of different quantities.
CONV(HEX(article_id), 16, 10) converts HEX(article_id) from hexadecimal (base 16) to decimal (base 10). Then, MOD(CONV(HEX(article_id), 16, 10), 2) computes the remainder when the converted decimal number is divided by 2.
(1) Create test data
<pre>
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `strnum_article_ids`;
CREATE TABLE `strnum_article_ids` (
  `article_id` char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
INSERT INTO `strnum_article_ids` (`article_id`, `content`) VALUES
('ap1p3le3', 'apple'),
('or2an3ge4', 'orange'),
('ba34na5na', 'banana'),
('wate4rle56mon', 'waterlemon'),
('ki78wi', 'kiwi');
</pre>
(2) Part 1
<pre>
SELECT *
FROM `strnum_article_ids`
WHERE MOD(CONV(HEX(article_id), 16, 10), 2) = 0;
</pre>
(3) Part 2
<pre>
SELECT *
FROM `strnum_article_ids`
WHERE MOD(CONV(HEX(article_id), 16, 10), 2) = 1;
</pre>


[[Category:Data_hygiene]]
[[Category:Data_hygiene]]
[[Category:Data Science]]
[[Category:Data Science]]
[[Category:MySQL]]
[[Category:MySQL]]
Anonymous user

Navigation menu