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…
Tag: sql
How use data in table as entity for key value in SQL?
I have a table as following: Is there any SELECT query to show table in following form? Thanks a lot. Answer You can try following code : UPDATE Since the table is containing more post_id’s, please check the following update.
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…
How to Select one Value for each row after Joining of 2 Tables
I have 2 tables, the first one has 10 distinct values: , each GlobalPnID has many values on the second table, I want to join 2 tables and select one random value of PortionKey of the second table that match the condition and move to the next GlobalPnID Answer
Getting Error as @Parameter1 is not a parameter for procedure
I am learning mvc from this video where I am getting data from a form and saving it to database. When I ran my code first it gave an error stating Procedure or function ‘spAddEmployee’ expects parameter ‘@Employee_Name’, which was not supplied. I followed a solution in which I initiali…
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
Postgres & Rust R2D2: How to get array_to_json as text/string without the escaped double quotes?
I have the following SQL: This gives me following in PSQL: When I put a ::text: I still get the same: However on my rust app’s side using r2d2_postgres, I get an escaped string instead: Rust code: Outputs: How I can I prevent the escaping of double quotes? Answer The quotes are only escaped during print…
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 …