Trying to write a function to see how often an object exists and give it a + 1 based on the number of times it exists.
Using sqlite database and python.
select distinct Date, Name from history order by Date Desc
Will return:
Date Name
2012-25-03 a
2012-25-03 b
2012-25-03 c
2012-25-03 d
2012-24-03 b
2012-24-03 c
2012-24-03 d
2012-24-03 e
2012-23-03 c
2012-23-03 d
2012-23-03 e
2012-23-03 f
Basically looking to accomplish the following in either python or sql:
a = 1
b = 2
c = 3
d = 3
e = 2
f = 1
I have attempted a few different approaches in python using iterators and subqueries, but haven’t been successful, maybe it can/should be done is sql.
Appreciate everyone’s time!
If there is a chance you have more than one row with same
DateandNameand you don’t want to doubly count those rows, change theCOUNT(*)to:(update) If your SQLite version does not support
COUNT(DISTINCT column), you could use a subquery in that case: