Skip to content

Tag: sql

Where am I going wrong in my cs50 pset 7 10.sql nested query?

I am currently trying to find the names of all people who have directed a movie that received a rating of at least 9.0 the scheme for these tables is MY SQL QUERY IS : This however fails the check50 test, and gives incorrect output. Can anyone help me with where I’m going wrong? Answer The spec says (em…

How to use count(‘condition’) over(partition by xx) in SQL

Here is the database: The first table is named Trip and the second table is Users. CLIENT_ID and DRIVER_ID are foreign keys for USERS_ID in the Users table. I want to find how many orders cancelled by the non-banned driver and non-banned passenger for each day (Trip.Status != ‘completed’ and Users…

SQL ARITHMETIC OPERATION

I am trying to get the sum of two rows using (+) operator in select. But when one column is null, the column for the SUM will also be null. If 2019 have sales amount of 20,000 and 2020 with 0 or null, the TOTAL_SALES will also be NULL I am wondering if there is a way to make the

Aggregate yearly data based on different months using SQL

I have a table ‘Amounts’ where I have the monthly payments of customers. Every customer has a row for each payment he has made. I want to aggregate their payments yearly starting from the month they paid first. For example in the table given below, for userID 132, I want to aggregate his payments …

SQL Subselect calculated in one row

I have a trouble getting an SQL select to work. I have one table – below is the example: I want to calculate the sum of every entry under 10 hits and every entry over 10 hits in one output. Like below: I tried inner join and outer join but I think that’s the wrong approach. If I do a

How to re-run Diesel migrations?

I’m using Diesel with PostgreSQL. I added my migrations, and they worked fine, outputting everything in the schema.rs file. Until I noticed that I was missing the created_at fields on some of my migrations. I edited the SQL and ran diesel migration run. Nothing happened, no errors, no success. Is there …