Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:38:35+00:00 2026-05-31T21:38:35+00:00

Trying to write a function to see how often an object exists and give

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:38:36+00:00Added an answer on May 31, 2026 at 9:38 pm
    SELECT Name
         , COUNT(*) AS cnt
    FROM history 
    GROUP BY Name
    ORDER BY Name
    

    If there is a chance you have more than one row with same Date and Name and you don’t want to doubly count those rows, change the COUNT(*) to:

         , COUNT(DISTINCT Date) AS cnt
    

    (update) If your SQLite version does not support COUNT(DISTINCT column), you could use a subquery in that case:

    SELECT Name
         , COUNT(*) AS cnt
    FROM 
        ( SELECT DISTINCT
              Name, Date
          FROM history 
        ) AS h 
    GROUP BY Name
    ORDER BY Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function that formats every (string) member/variable in an object,
I am trying to write a function in C++ that solves for X using
(Important: See update below.) I'm trying to write a function, import_something , that will
I'm trying to write a validation function that checks to see if an entry
I'm trying to write predicate function for use with STL algorithms. I see that
I'm trying to write my own modal popup window using a jQuery function. However,
I am trying to write simple function that checks to see if a designer
I'm trying to write a C function using OpenSSL/libcrypto to calculate the SHA256 sum
I'm trying to write a TTL decorator in python. Basically I give it raise
I am trying write a function that generates simulated data but if the simulated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.