Is it possible to transpose a table with repeated columns? Existing table: user_id question_id body 1 1 ‘Text1 1’ 1 1 ‘Text1 1-2’ 1 2 …
Tag: sql
Insert values if records don’t already exist in Postgres
I’d like to get this working, but Postgres doesn’t like having the WHERE clause in this type of insert. Answer In Postgres, there is a really nice way to do that: hope that helps.-
How to stop a search into a database when I already have results
I will post my code and explain after: db = sqlite3.connect(“Gene.sqlite”) cur = db.cursor() cur.execute(“SELECT * FROM Table”) for i in cur.fetchall(): if i[0] == name: print ‘‘ ‘&…
MySQL error with Not unique table/alias with join
I have this sql query which gives me the error “Not unique table/alias”. This is not the case as “studii” is the only table with that name. Why does this error show up? Answer in this care you are referring to 2 different selections of a table with the same alias (studii)
How to check if the Default Value Constraint exists?
I am using SQL server 2008. I need to find if default value constraint does not exist then create it. Here is what I have tried. IF (NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA….
Update one table based upon SUM(values) in another table on multiple criteria
I can’t seem to find out how to do this and not sure exactly how to search for it! I have a table [MASTER]: ID varchar(6) CCY varchar(3) Val1 decimal(20,5) Val2 decimal(20,5) FOO decimal(20,5) and …
SQL Select Value From Comma Delimited List
I have a field in my database called “Notes”. It contains a comma delimited list of values. I want to perform a SELECT Query that only returns the first value in the “Notes” field. This query would …
Oracle: how to get percent of total by a query?
I have the following query and its result is very unexpected to me: select stato, (count(1) *100) / sum(1) from LOG_BONIFICA group by stato; it returns 100 for all rows. Should it be different ?
ISDATE() equivalent for MySQL
I have a line of code for SQL server which takes a date listed as “YYYYMMDD” where the DD is 00 and converts the 00 to 01 so that it works with datetime. I would like to be able to use MySQL for it the current code which works for SQL server: but isdate is not valid in MySQL, what
Python SQLite how to get SQL string statement being executed
Let’s say we have a SQL statement that just needs to be completed with the parameters before getting executed against the DB. For instance: How do I get the string that is parsed and executed?, something like this: In this simple case it’s not very important, but I have other SQL Statements much m…