Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting values from SQLite database in Python
    primarykey
    data
    text
    <p>I was trying to figure out how to work with SQLite database using python, but seem to be stuck. I think I am missing something basic. I was following this tutorial: <a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">http://docs.python.org/library/sqlite3.html</a></p> <p>I set up a database such that it contains the following information:</p> <pre><code>import sqlite3 conn = sqlite3.connect('SQL_test_3') #this creates a seperate file c = conn.cursor() c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''') data = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), ('2006-04-06', 'SELL', 'IBM', 500, 53.00), ] for t in data: c.execute('insert into stocks values (?,?,?,?,?)', t) conn.commit() c.close() </code></pre> <p>My problems arise when I try to extract the data; the tutorial explains how to extract the data if one of the characteristics are satisfied, for example:</p> <p>(When I open the database in another file)</p> <pre><code>import sqlite3 conn = sqlite3.connect('SQL_test_3') c = conn.cursor() price = 53 t = (price,) c.execute('select * from stocks where price=?', t) print c.fetchall() </code></pre> <p>The above works perfect, but what if I want extract information for all the assets who's price is greater that 50, I can't do it. Doing price > 50 and price>? doesn't work...</p> <p>So my questions are:</p> <p>1) How do I extract information for an asset when the key criteria is fits in a given range, for example price > 50 or 40 &lt; price &lt; 70.</p> <p>2)And what if I wanted to have two criteria, for example information for IBM stocks, and if the stock was traded at, say, price greater than 50.</p> <p>I feel that my questions are very beginner/basic, but I couldn't find the answers to them in the tutorial.</p> <p>Any help is appreciated.</p> <p>Thanks in Advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload