Questions tagged [sql]
The sql tag has no usage guidance.
131 questions
0
votes
1
answer
21
views
CS50SQL(2024) - PSET 3 - Meteorite Cleaning - New table "meteorites" order by year and name check50 output difference
I am having problems matching the check50 output with my code, even though it properly orders the meteorites by year and name, from my opinion. Moreover, it assigns the IDs starting with 1 from the ...
0
votes
0
answers
5
views
How to change a default field id value of a class in django models
Here is my model
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
pass
class Auction_categories(models.Model):
Auction_category = ...
0
votes
1
answer
36
views
Check if added value corresponds to value/id from another table - SQL Final Project
I'm working on SQL Final project and I decided to create a database for a gym franchise.
How can I make sure that a client can join classes only to which they have a card for (correct access level and ...
1
vote
0
answers
319
views
parse error: no such table
I'm currently on week 1 of cs50's SQL course, running into some issues with the exercise.
Running the code from both the file and the terminal results in a no such table, despite me already ...
0
votes
1
answer
214
views
CS50 Meteorites Cleaning
Quick Question for yall, so I set .nullvalue to "NULL" before writing my table updates. Second question, how do I rearrange columns in my final meteorites table that was it passes the CS50 ...
0
votes
1
answer
74
views
Finance pset, cs50's SQL INSERT statements results in runtime error
I'm trying to write a buy() function which would update user's stocks and his balance.
I've added two new tables to my finance.db: stocks table for storing user's stocks and transactions table for ...
0
votes
2
answers
348
views
CS50 SQL problem set 3 Meteorite Cleaning: NULL values are not present in "meteorites" table
Problem link: https://cs50.harvard.edu/sql/2023/psets/3/meteorites/
As the problem mentioned, any empty values in meteorites.csv are represented by NULL in the meteorites table.
When I run the sqlite3 ...
1
vote
1
answer
84
views
cs50x Ps7 Movies 10.sql
On the Pset page it says that the solution must have 3392 rows. I wrote two different solutions, both accepted by check50, with different number of rows.
The first one gives 3389 lines:
SELECT ...
0
votes
1
answer
82
views
CS50 pset9: Why does 'SELECT last_insert_rowid()' return 0 instead of the expected value when using CS50 SQL library in Flask?
symbol_id = db.execute("SELECT symbol_id FROM symbols WHERE symbol = ?", quote["symbol"])
if not symbol_id:
db.execute("INSERT INTO symbols (symbol) VALUES ...
0
votes
1
answer
54
views
SQL subqueries conditions ignored in Fiftyville Pset
I'm trying to call a select subquery where some conditions have to be met:
SELECT * FROM people
JOIN bakery_security_logs ON people.license_plate = bakery_security_logs.license_plate
WHERE people....
0
votes
0
answers
165
views
In PSET7 Movies, SQL.12 - issue with `and`
The below query doesn't work for reasons that are unclear to me. If I replace and with or, the query works, though not in the way specified by the problem. Why wouldn't and work in this case?
-- write ...
0
votes
1
answer
406
views
ValueError: UNIQUE constraint failed: on finance pset9, could someone point me in the right direction on which values should be UNIQUE from my table?
Could someone help me figure out which values should I define as UNIQUE? I'm getting the ValueError: UNIQUE constraint failed: compras.id beacuase of the way I created my table for keeping tab of who ...
0
votes
1
answer
284
views
CS50 PSET7 Movies "query did not return results" 12.sql
First timer asking on Stack Exchange. I have a SQL query that returns 6 results in the terminal but does not work with check50 resulting in
"Query did not return any results"
I read in a ...
1
vote
1
answer
69
views
PSET7/SQL Any clues as to why my logic isn't working? (13.sql)
This very nested query is to return names of all the actors that performed on a Kevin Bacon film. Instead it's returning nothing, any ideas are appreciated!
Note: I'm yet to implement the part that ...
0
votes
1
answer
318
views
SQL QUERY MOVIES.DB
I have written the query for 6.sql but it does not work.
SELECT AVG(rating) FROM ratings
WHERE movie_id = (SELECT id FROM movies
WHERE year = 2012);
I can do this by using JOIN
SELECT AVG(rating) ...
0
votes
1
answer
863
views
Pset 7 Fiftyville
I am quite sure about my answers but check50 keeps saying its incorrect. Im not sure if I am giving the answers in the correct way. For ex. The thief escaped to Heathrow(I think)/ London but I am not ...
0
votes
1
answer
630
views
PSET 9 Finance index.html issue with displaying table results with html
I'm currently on CS50 PSET 9 Finance and stuck on the index.html portion of the assignment.
This is my code from assignment.py:
@app.route("/")
@login_required
def index():
stocks = db....
1
vote
1
answer
27
views
How do we delete existing flight in sqlite via Django?
In the notes for the SQLITE section, week 3,
https://cs50.harvard.edu/web/2020/notes/4/#:~:text=delete%20your%20existing%20flight%20from%20New%20York%20to%20London
It states:
Every time we make ...
0
votes
1
answer
233
views
Week 9 - I need a help about UNIQUE constraint
I am solving the week 9 problem using python. And I am interested in knowing how to deal with the error below using the if and elif?
For example:
rows = db.execute("SELECT username FROM users ...
0
votes
0
answers
461
views
Sqlite3 ProgrammingError in Python (Flask, helper.py file)
I am currently working on my final project, a web application using flask, SQL and javascript. I came across this issue:
`sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Cannot operate on ...
0
votes
1
answer
715
views
pset7 Fifty Ville // not sure how to get the intersect of cases to find the thief
I am currently doing pset7 and I have found most of the clues of who it is but the problem is that I need to use the intersect sql function to find the common name of the thief but I am not sure how.
...
0
votes
1
answer
481
views
CS50 SQL Library use outside of CS50 IDE
I am trying to create a SQlite database following Dr Malan's class example. The difference is that I am doing it outside of the CS50 IDE. For some reason the below code does actually create the .db ...
0
votes
1
answer
83
views
DIFFERENCE BETWEEN TWO SQL CODES
I wrote these two codes for SQL pset7 but I'm getting different answers. Can anybody tell me the cause of the difference?
SELECT COUNT(title) FROM movies WHERE id = (SELECT movie_id FROM ratings WHERE ...
0
votes
1
answer
333
views
How to use a PostgreSQL database using python CS50 library's SQL function?
I wanted to use the CS50 library's SQL function for interacting with a PostgreSQL database.
I have installed PostgreSQL on my computer and removed the need for passwords by modifying the .../Program ...
0
votes
1
answer
405
views
CS50 finance SELL - Cannot get the code to subtract the stock from the database or index
I have tried a number of versions of this code, except I cannot get it to subtract shares from my ("/") index page it does nothing and shows nothing in the shares column in the transaction ...
0
votes
1
answer
100
views
Project: Conditional style for html table
I have a table in html which gets the data from a SQL query in PY. One of the columns in my SQL table is type (tp). I want the html table to show one color for each row of the same type and another ...
0
votes
1
answer
75
views
pset 7 houses passes check 50 but shows the names 4 times
I have a really strange problem here: both import and rooster passes every check in check 50, but if I run Rooster the names on every house appear 4 times. I have no clue about why this is happening, ...
0
votes
1
answer
196
views
FINANCE: GROUP BY doesn't add up the numbers of shares of the same stock
So in index i'm trying to display a table with all the stocks that the user has bought, one row for each stock, displaying the total number of shares in the user's portfolio along with the total value ...
0
votes
1
answer
171
views
PSET8 Finance Buy. SQL query not executing
My buy function is crashing at the SQL query where I'm trying to insert data from the transaction into a transactions table. The types of each column are transaction_id(integer, primary key), user_id(...
0
votes
1
answer
225
views
CASH NOT UPDATING - FINANCE SELL
so everything I have so far is working except the part where I need to update the cash right after I sell a stock. As you can see in the table below what's happening is that everytime I sell a stock ...
1
vote
1
answer
1k
views
PSET 7 Movies SQL Q9
In 9.sql, write a SQL query to list the names of all people who starred in a movie released in 2004, ordered by birth year.
...Your query should output a table with a single column for the name of ...
0
votes
1
answer
206
views
Problem taking a SUM with SQL to python
I am doing Finance and I am fighting with this code... could anyone help me?
I want to "select" some data from a sql table and put this value to a variable in python (a specific FLOAT number)...
0
votes
1
answer
71
views
PSET 7 HOUSES - Syntax error on case function
I'm trying to select the first name and last name and ONLY select the middle name when there is one. The logic of my query makes sense. Every time I am extracting the first name, last name, and birth. ...
0
votes
1
answer
413
views
pset7 Q10 Weird Result
The challenge is apparently straightforward: write an SQL query to list the names of all people who have directed a movie that received a rating of at least 9.0.
To get from names (which lives in the '...
0
votes
0
answers
29
views
Final Project: dynamic page creation to show just 10 SQL entries per page
I'm developing a web-page for my CS50's Final Project for contacting japanese students around Argentina. The only official japanese exam takes place in Buenos Aires, and there are no many good places ...
0
votes
1
answer
220
views
Finance - Missing Value For Placeholder
As far as I can tell, I have the value set - username = username. Am I missing something stupid here?
Code:
@app.route("/register", methods=["GET", "POST"])
def ...
0
votes
1
answer
332
views
Pset7 (Movies) 12.sql: Table outputs 96 rows rather than 5 rows
I've been stuck on this for quite some time and did a lot of research on the AND operator in SQL, but no matter how many variations I try I cannot get my table to output just 6 rows, with each row ...
0
votes
1
answer
272
views
PSET 7 - 6.sql, terminal just hangs
PSET 7 for 6.sql, Terminal just hangs when I execute it. Can anyone tell me why this wouldn't work? I've tried every variation I could think of (and several I found online) for this and none of them ...
0
votes
1
answer
190
views
Pset7 Movies Q12: I don't get what's wrong
I can't figure out why my pset7 movies Q12 code isn't working. Can anyone tell me why?
Here is my code:
SELECT DISTINCT title FROM movies, stars, people WHERE movie_id IN (SELECT movie_id FROM stars ...
0
votes
1
answer
113
views
Can't import books.csv using import.py
I'm on a project1, here is the link to it: https://docs.cs50.net/ocw/web/projects/1/project1.html
I've successfully made a Table books using my Python script, however when I try to import the "books....
0
votes
1
answer
273
views
CHECK50 Bug in pset7: movies SQL
I have been banging my head on this for an hour and half. Finally finished the pset, uploaded it.
Check 50 says:
Now, both cs50 ide and DB browser return the correct results, and number of lines for ...
1
vote
1
answer
308
views
Finance: Ensuring no duplicate usernames
I've implemented the following code in my "/register" route:
def register():
"""Register user"""
if request.method == "GET":
return render_template("register.html")
else:
#...
0
votes
1
answer
391
views
PSET7 Movies Q8 - Why these queries return different results?
I'm working on pset7 movies problem of the CS50 course and I have a question regarding 8.sql, which asks to write a SQL query to list the names of all people who starred in Toy Story.
To my ...
0
votes
1
answer
765
views
Pset 7 Movies - 13.sql "Error When Executing Query - Too Many Statements at Once"
I'm working on Pset 7 "Movies" and check50 shows an error for 13.sql (list of Kevin Bacon's co-stars) when I submit my code despite running successfully in the IDE.
The exact error message is Error ...
0
votes
1
answer
84
views
Pset7 Houses, what does my error message mean?
Whenever I run my code, I get a strange error message because of my code. It is because of my SQL code, but I followed all of the instructions, and even tried some other SQL code, which worked ...
0
votes
0
answers
156
views
Deleting SQL dynamically with Flask
I want to delete a specific row in my database but I don't know how to do it.
On my HTML I have this:
<div class="cases">
{% for row in rows %}
<div class="card border-success mb-...
0
votes
1
answer
23
views
Difference between { var } vs :var as placeholder - SQL, Postgre
I was wondering if it's a good idea to use { var } in place of :var as placeholder?
This is what I see in CS50 notes:
flight = db.execute("SELECT * FROM flights WHERE id = :id", {"id": flight_id})....
0
votes
0
answers
199
views
How to ensure proper database url in environment variable?
I am trying to run the code from lecture3 and I am having trouble ensuring the database url is properly set using the environment variable. Here's the code:
db_url = 'postgresql+psycopg2://{username}:...
0
votes
1
answer
725
views
pset7/movies/13.sql: exclude Kevin Bacon from the resulting list
In pset7/movies, I want to dynamically exclude Kevin Bacon from the resulting list (e.g. not specifically mentioning his name with NOT or EXCEPT or copying and pasting code that calculates his ID, so ...
0
votes
1
answer
149
views
CS50w Project1: Trouble posting reviews (Row Proxy error - how to ensure a tuple)
The last bit I am struggling with on Project1 is posting a rating and review.
I continually get
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'RowProxy'
[SQL: INSERT ...