Equating a table value to another value in another table

I have a small problem with a program I am writing. I have a spreadsheet - stocks containing information (groceries, barcodes, etc.) about items stored in the refrigerator. Then I have another store that works like a store containing many products and their barcodes. Some of the products in the store table are in the stock table at the moment, and there is a boolenan field called "stock" which says if this product is in the stock table or not, if it is 1, it is in the refrigerator, if it is 0, it is not in the refrigerator. The two fields in the inventory table are quantity and quantity. Currently, the amount is in the refrigerator, the amount of which should be in the refrigerator at any time. When something is taken out of the refrigerator,the quantity of that product quantity is reduced by 1. Each barcode in the inventory table has a corresponding number in the store table. I need to make a database query from a python program that will order products from a store table when the quantity (what is in the fridge) is less than the quantity (what should have been in the fridge at any time). Therefore, you need to take the barcode of the row in the stock table where the amount is less than the quantity and corresponds to that barcode in the store table. Then on the line of that barcode, you need to set value = 1.when the amount (what is in the refrigerator) is less than the amount (what should have been in the refrigerator at any time). Therefore, you need to take the barcode of the row in the stock table where the amount is less than the quantity and corresponds to that barcode in the store table. Then on the line of that barcode, you need to set value = 1.when the amount (what is in the refrigerator) is less than the amount (what should have been in the refrigerator at any time). Therefore, you need to take the barcode of the row in the stock table where the amount is less than the quantity and corresponds to that barcode in the store table. Then on the line of that barcode, you need to set value = 1.

I would be very glad if someone could help me with this as it is really difficult for me to write this function. Below are the validation and validation functions if it helps.

arrival

def check_in(): 
    db = MySQLdb.connect(host='localhost', user='root', passwd='$$', db='fillmyfridge')
    cursor=db.cursor(MySQLdb.cursors.DictCursor)
    user_input=raw_input('please enter the product barcode that you wish to checkin to the fridge: \n')
    cursor.execute("""update shop set stock = 1 where barcode = %s""", (user_input))
    db.commit()
    numrows = int(cursor.rowcount)
    if numrows >= 1:
        row = cursor.fetchone()
        print row["product"]
        cursor.execute('update stock set amount = amount + 1 where product = %s', row["product"])
        db.commit()
        cursor.execute('udpate shop set stock = 1 where barcode = user_input')
        db.commit()
    else:
        new_prodname = raw_input('what is the name of the product and press enter: \n')
        cursor.execute('insert into shop (product, barcode, category) values (%s, %s, %s)', (new_prodname, user_input, new_prodname))
        cursor = db.cursor()
        query = ('select * from shop where product = %s', (new_prodname))
        cursor.execute(query):
        db.commit()
        numrows = int(cursor.rowcount)
        if numrows<1:
            cursor.execute('insert into atock (barcode, quantity, amount, product) values (%s, 1, 1, %s)', (user_input, new_prodname))
            db.commit()
            cursor.execute('insert into shop (product, barcode, category, stock) values (%s, %s, %s, 1)', (new_prodname, user_input, new_prodname))
            print new_prodname 
            print 'has been added to the fridge stock'
        else:
            cursor.execute('update atock set amount = amount + 1 where product = %s', (new_prodname))
            db.commit()
            cursor.execute('insert into shop (product, barcode, category, stock) values (%s, %s, %s, 1)', (new_prodname, user_input, new_prodname))
            print new_prodname 
            print 'has been added to the fridge stock'

      

photos

import MySQLdb

def check_out():
    db = MySQLdb.connect(host='localhost', user='root', passwd='$$', db='fillmyfridge')
    cursor=db.cursor()
    user_input=raw_input('please enter the product barcode you wish to remove from the fridge: \n')
    query = cursor.execute('update stock set instock=0, howmanytoorder=howmanytoorder + 1, amount = amount - 1 where barcode = %s', (user_input))
    if cursor.execute(query):
        db.commit()
        print 'the following product has been removed from the fridge nd needs to be ordered'
        cursor.execute('update shop set stock = 0 where barcode = %s' (user_input)
        db.commit()
    else:
        return 0

      

-1


source to share


2 answers


So, if I'm right, you have the following tables:

Stock with at least barcode, quantity and quantity column

Shop with at least barcode and stock post

I don't understand why you need this column in the store table, because you can easily get the products that are in stock using a join like this:



SELECT barcode, ... FROM Stock ST JOIN Shop SH ON ST.barcode = SH.barcode;

      

Obviously, you have to select some other columns from the Shop table as well, otherwise you could just select everything from the Stock table.

You can get a list of products to order (where the amount is less than the quantity):

SELECT barcode FROM Stock ST WHERE ST.amount < ST.quantity;

      

+1


source


Try to keep the question shorter. I think this will give more answers.



0


source







All Articles