Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:13+00:00 2026-05-29T10:04:13+00:00

I was trying to figure out how to work with SQLite database using python,

  • 0

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: http://docs.python.org/library/sqlite3.html

I set up a database such that it contains the following information:

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()

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:

(When I open the database in another file)

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()

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…

So my questions are:

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 < price < 70.

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.

I feel that my questions are very beginner/basic, but I couldn’t find the answers to them in the tutorial.

Any help is appreciated.

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:04:15+00:00Added an answer on May 29, 2026 at 10:04 am
    c.execute('select * from stocks where price > ?', (50,))
    
    c.execute('select * from stocks where price between ? and ?', (40, 70))
    
    c.execute('select * from stocks where price > ? and symbol = ?', (50, 'IBM'))
    

    Is this ok or do you need a universal solution?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bah, vbscript. I'm trying to figure out how to get this statement to work:
Trying to figure out the best way to do this: Should I do something
I'm trying to figure out why insertNewObjectForEntityForName is not working. I assume it's something
I've been trying figure out how to add a handler to a method using
I am trying to figure out how exactly does treesort from here work (I
What I'm trying to figure out is if something such as this (written in
I've been trying to figure out how to work this jQuery Form plugin to
I'm debugging through a new codebase and trying to figure out how things work
I'm trying to figure out how data binding with BindingSource is supposed to work
I have spent so much time trying to figure out how numbers work in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.