Skip to content

Tag: sqlite

SQL count when equation of two columns are true

I have a sheet with rows (id and year). See below: id year 101 2002 101 2006 101 2010 101 2014 101 2018 102 2002 102 2006 102 2010 102 2014 103 2010 I simply want to regroup and reformat my table to look like this: id 2002 2006 2010 2014 2018 101 1 1 1 1 1 102 1

SQL MAX(col1, col2) with priorities

I need to select row with MAX(val1) for each group. If there is more than one row with equal val1 = MAX(val1) I need to select from them row with MAX(val2), etc. In pseudo code it should be like this: For example: I have table nums with one TEXT column name and three INTEGER columns — id, num1 and num2

Python SQL: storing objects or iterables

Assume I want to store via sqlite3 a simple list of strings: or a python object with properties and methods. What I tried so far is to serialize (pickle) my_list, and the returned byte representation is b’x80x03]qx00(Xx01x00x00x00aqx01Xx01x00x00x00bqx02Xx01x00x00x00cqx03e.’. However, cannot be st…

SQL query for entries of last N jobs

I have the following table: etc, so basically jobs keep adding entries concurrently I am looking for an efficient query to return all entries of the latest (by time) N jobs So find the first (by time) entry for each job, then using that get the latest N jobs with all their entries So for the above table and N…

Unable to use Cursor in separate function

I’m currently tryign to learn how to use SQLite3 and am trying to seperate setting up the DB through functions. My second function is where I’m having the error : AttributeError: ‘NoneType’ object has no attribute ‘cursor’. After looking at the SQLite3 doucmentation, I got …

sqlite3 INSERT INTO UNION SELECT

Table columns: pk is the auto-incrementing primary key An error occurs when I execute this SQL DB Error: 1 “table table1 has 4 columns but 3 values were supplied” Answer You should explicitly specify which columns in table1 your insert is targeting: When you omit the select list entirely, SQLite w…