Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Splitting of articles by article ids
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Case1: Articles Numbered IDs == If the article number is a digit, split the article into two parts based on a remainder of 0 or 1, resulting in two nearly equal halves. (1) Part1 <pre> SELECT * FROM articles WHERE MOD(article_id, 2) = 0; </pre> (2) Part2 <pre> SELECT * FROM articles WHERE MOD(article_id, 2) = 1; </pre> == Case2: Articles IDs which mix of string and number == If the article ID consists of numbers or text e.g. [https://en.wikipedia.org/wiki/Amazon_Standard_Identification_Number Amazon Standard Identification Number], 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 Science]] [[Category:MySQL]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)