im new in programing, starting with python I found this script in a post (link below) query = ‘SELECT * FROM {}’.format(table) c.execute(query) How to use variable for SQLite table name it worked, …
Tag: sql
PostgreSQL Query To Obtain Value that Occurs more than once in 12 months
I have the following query to return the number of users that booked a flight at least twice, but I need to identify those which have booked a flight more than once in the range of 12 months SELECT …
Double quotes problems with Postgres
I am using Django with postgres. Here’s the snippet of my code which I am using to create tables in the db. My question is: why is the user table getting renamed as “user” (with quotes) why is the role_id getting named as role_id_id where as I have clearly mentioned role_id to be my column name? Answer After reading few
SQLite Select data where the column name contains a string and create a table with those headers only
Following from the answer to this question: SQLite Select data where the column name contains a string? I would like to know how to create a table with these new columns obtained from the previous table. I wrote something like this (Please ignore the WHERE statement): however, it is not working. Any help in this direction would be much appreciated.
Mysql group by get value base of another colum value
I have one long query return like below table Could I use group by to achieve below result Basically, i would like to to group name , and the value is based on priority without join the query itself Answer You can use row_number()
doing some of columns based on some complex logic in pyspark
Here is the question in the image attached: Table: So result column is calculated based on the below rules: If col3 >0 , then result=col1+col2 If col 3=0, then result= sum (col2) till col3 >0 + col1(where col3>0) for example for row =3, the result=60+70+80+30(from col1 from row 5 because here col3>0)=240 for row=4, the result=70+80+30(from col1 from row 5
How to format query result to show result in a specific json output
I am trying to learn how to format my result from SQL query to have my output as JSON. I will really appreciate if someone could guide as I will generate my results in different types of charts. For instance, one chart need to have the following JSON structure: and I am using Northwind stored procedure With the above I
Update the timestamp values in a column so that the latest timestamp is current time while maintaining the relative time difference between rows
I have a table in a Postgres database with a column whose values are timestamps for a period of time in the past. How can I update the values in that column so the highest value (the most recent timestamp) is the current timestamp, keeping the same interval between the other ones? For example, if the current values are: and
How to cast varchar on update?
When I update t1 then “VALUE” field should increment but this field is set to VARCHAR and I would cast it to INTEGER: Answer You will need to cast “VALUE” to an integer to be able to increment it, so: Firebird will automatically convert the INTEGER back to a VARCHAR on assignment. See this dbfiddle. That said, the proper way
Group rows on condition PostgreSQL
I have a table with repeated Column1 and Column2 pairs, let’s say this is ‘many-to-many’ table. Also, I have there one extra integer column – Column3. What I want is select conditionally grouped rows, like 1). If pair of Column1 and Column2 have several records contains 5 value among others – then it should be grouped into one row with