?
Solved

Queuing system help

Posted on 2011-02-15
3
Medium Priority
?
395 Views
Last Modified: 2012-05-11
I'm trying to build a kind of queuing table. We are offering items for sale on a daily basis, kind of like woot.com. It is called Daily QuickDeals. Now, I need a script to go through all the records in linv_quick_deals to determine:

1

Is the product not sold out

2

has it not been listed as a QuickDeal in the last 2 days

And if it meets the above criteria, return the inventory_id so I can insert a record into linv_todays_deal with today's date and the inventory_id.

The below isn't working as I expect because it keeps putting inventory_id 1 in when it is sold out.

I'm thinking that I may have a bad design. Should I just either, move the sold_out column to the linv_quick_deals table or remove the record from the linv_quick_deals table when it is sold out?

Any ideas or suggestions will be appreciated.

SELECT `inventory_id` 
FROM   linv_quick_deals i 
WHERE  `inventory_id` NOT IN (SELECT d.`inventory_id` 
                              FROM `linv_todays_deal` d
                              WHERE d.`inventory_id` = i.`inventory_id` 
                              AND   d.`sold_out` <> 0
                              AND   DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= d.`deal_date`)

Open in new window

Data:
CREATE TABLE `linv_todays_deal` (
	`deal_id` INT(10) NOT NULL AUTO_INCREMENT,
	`inventory_id` INT(10) NOT NULL DEFAULT '0',
	`deal_date` DATE NULL DEFAULT NULL,
	`sold_out` TINYINT(4) NULL DEFAULT '1',
	PRIMARY KEY (`deal_id`),
	INDEX `idx_inventory_id` (`inventory_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT;

deal_id 	inventory_id 	deal_date 	sold_out
1 		2 		2011-02-14 	1
2 		1 		2011-02-10 	0


CREATE TABLE `linv_quick_deals` (
	`inventory_id` INT(10) NOT NULL AUTO_INCREMENT,
	`user_id` INT(11) NOT NULL,
	`title` VARCHAR(50) NOT NULL COLLATE 'utf8_unicode_ci',
	`description` TEXT NOT NULL COLLATE 'utf8_unicode_ci',
	`attributes` TEXT NOT NULL COLLATE 'utf8_unicode_ci',
	`order_link` VARCHAR(500) NOT NULL COLLATE 'utf8_unicode_ci',
	`image_link` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
	PRIMARY KEY (`inventory_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT;

inventory_id 	user_id title 	description 	attributes 	order_link 	image_link
1 		23 	Item 1 	<SNIP>  	<SNIP> 		<SNIP>		<SNIP>
2 		23 	Item 2 	<SNIP>		<SNIP>		<SNIP>		<SNIP>

Open in new window

0
Comment
Question by:EddieShipman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
jar3817 earned 1600 total points
ID: 34897016
Your linv_quick_deals table doesn't have an "out of stock" column, so can't select products from that table based on whether they're in stock or not.
0
 
LVL 6

Assisted Solution

by:Ferrosti
Ferrosti earned 400 total points
ID: 34897231
Usually one would go for an item_master table and an item_stock table.
In lineitem one would have itemdetails, while stockitem holds information about reservation, quantity, qty_threshold etc.
Problem is that in case of phone calls an agent might tell the customer of a valid stock and two minutes later he could not book it to the customers order. For this case one would reserve an item as soon as a customer agent got its record open.
0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 34901519
Decided to put the sold_out column in the linv_quick_deals table
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question