Skip to content

Instantly share code, notes, and snippets.

@bloodyburger
Created April 19, 2021 07:35
Show Gist options
  • Save bloodyburger/36e938bfa0cdca93620d347c59a3b0b2 to your computer and use it in GitHub Desktop.
Save bloodyburger/36e938bfa0cdca93620d347c59a3b0b2 to your computer and use it in GitHub Desktop.
Iowa Liquor Sales Dataset to MySQL
## Download
https://mydata.iowa.gov/Sales-Distribution/Iowa-Liquor-Sales-by-Year-and-County/ahiv-u4uz
## mysql
CREATE TABLE `iowaalcohol` (
`DATE` date DEFAULT NULL,
`CONVENIENCE STORE` varchar(255) DEFAULT NULL,
`STORE` varchar(12) DEFAULT NULL,
`NAME` varchar(255) DEFAULT NULL,
`ADDRESS` varchar(255) DEFAULT NULL,
`CITY` varchar(255) DEFAULT NULL,
`ZIPCODE` varchar(20) DEFAULT NULL,
`STORE LOCATION` varchar(255) DEFAULT NULL,
`COUNTY NUMBER` varchar(4) DEFAULT NULL,
`COUNTY` varchar(255) DEFAULT NULL,
`CATEGORY` varchar(20) DEFAULT NULL,
`CATEGORY NAME` varchar(100) DEFAULT NULL,
`VENDOR NO` varchar(20) DEFAULT NULL,
`VENDOR` varchar(255) DEFAULT NULL,
`ITEM` varchar(20) DEFAULT NULL,
`DESCRIPTION` varchar(255) DEFAULT NULL,
`PACK` int(11) DEFAULT NULL,
`LITER SIZE` int(11) DEFAULT NULL,
`STATE BTL COST` float(7,2) DEFAULT NULL,
`BTL PRICE` float(7,2) DEFAULT NULL,
`BOTTLE QTY` int(11) DEFAULT NULL,
`TOTAL` float(12,2) DEFAULT NULL,
KEY `STORE` (`STORE`),
KEY `DATE` (`DATE`),
KEY `CATEGORY NAME` (`CATEGORY NAME`),
KEY `CATEGORY` (`CATEGORY`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
## Translate the dates, clean up numbers, pre-import via bash
sed -E "s#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#" < iowa-liquor.csv |
tr -d '$' > iowa-liquor-datefixed.csv
## Load to MySQL
LOAD DATA LOCAL INFILE '/home/users/iowa.csv' INTO TABLE sales FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 ROWS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment