Skip to content

Tag: python

Transforming SQL Query to Django Expression

Assuming I have the following Django models and the according SQL-Tables with some data. I have simplified the models so that it is clearer. UserAnswer: id answer partquestion_id 1 667 1 PartQuestion: id question_id part_id 1 1 1 Solution: id content question_id 1 667 1 2 85 2 I want to get all User answers w…

SQLAlchemy group by day in timestamp column

I have an ORM (Model) defined in SQLAlchemy as below: I’m planning to get the sum of all views in each day and tried to group the results based on their end_to. I have used the following query in sqlalchemy: But this query throws this error: I am using the timestamp in my model and I don’t plan to…

update with csv file using python

I have to update the database with the CSV files. Consider the database table looks like this: The CSV file data looks like this: As you can see the CSV file data some data modified and some new records are added and what I supposed to do is to update only the data which is modified or some new records

JSON Blob into SQL Server

I have data from a web API that I want to store in a SQL database. Each record in the web API looks like this: Answer That query is invalid. Should be of the form INSERT INTO TableName(Column1, Column2) VALUES (?,?), so something like:

How to combine columns, group them then get a total count?

Below is a table that has candidate_id, two interviews they attended with the interviewer’s name, and results for each interview. candidate_id interview_1 interview_2 result_1 result_2 1 Interviewer_A Interviewer_B Pass Pass 2 Interviewer_C Interviewer_D Pass Reject I need help to combine column intervi…

How to format SQL Queries inside PySpark codefile

I would like to format my existing SQL queries inside the PySpark file. This is how my existing source file looks like: And this is how I wanted it to look like: I have already tried using black and other vscode extensions for formatting my code base but no luck since the SQL code is being treated as a python