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 8698221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:41:07+00:00 2026-06-13T01:41:07+00:00

i am using cursor for retrieving data from database but problem is that i

  • 0

i am using cursor for retrieving data from database but problem is that i have no. of records for same date and i want only one record date wise and related Tamt of date will be added to amount field:

I have database records like :

Sr    ExpName       Date       Camt  Tamt
---   --------- -----------   ----- -----
1     Pen        10-10-2012      10    10
2     abc        10-10-2012      30    45
3     xyz        11-10-2012      15    55
4     ggg        11-10-2012      20    75
5     aaa        11-10-2012      10    85
6     nnn        11-10-2012      10    95


 dbhelper = new DbHelper(this);
 db = dbhelper.getReadableDatabase();

    Cursor c = db.query(DbHelper.TABLE_NAME, new String[]{"CAST(Date AS DATE)","SUM(Tamt) AS AMT"}, null, null,"CAST(Date AS DATE)", null, null);
    adapter = new SimpleCursorAdapter(this, R.layout.myrow1, c, new String[]{DbHelper.C_Date,DbHelper.C_Tamt},new int[]{R.id.textView3,R.id.textView5} );
    startManagingCursor(c);     
    lstExpense.setAdapter(adapter); 

where myrow1 is a layout file in and TextView3 and TextVew5 field where i want to display output DATE and AMOUNT.

And i want ouput like this:

DATE             AMOUNT
------------     ------
10-10-2012          40
11-10-2012          35
12-10-2012          10
13-10-2012          10
  • 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-06-13T01:41:09+00:00Added an answer on June 13, 2026 at 1:41 am

    This sounds like a problem for GROUP BY and the SUM aggregation function.

    Working with SQLite directly your query would need to be along the lines of

    SELECT Date, SUM(Camt) AS Amount FROM Expenses GROUP BY Date;
    

    (I’ve assumed that your database table is called Expenses.)

    Converting this into an Android cursor query is then pretty simple

    Cursor c = db.query("Expenses", 
        new String[] { "Date", "SUM(Camt) AS Amount" }, 
        null, null, "Date", null, null, null);
    

    That should give you the result that you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a custom Adapter class. And retrieving data from database using cursor.
I've fetched the records from Database using Cursor. It works perfectly, but, I get
I am retrieving data from database using select query.My requirement is i have to
I have 1-50 records in the database. I am fetching those data using cursor
I have a stored procedure in oracle which is using cursor.Its fetching the data
I've populated a ListActivity from a Cursor using SimpleCursorAdapter that starts another activity when
I have some problem with the cursor when using JOprionPane. I set a cursor
I wan't to get data's from CallLog.Calls.CONTENT_URI in non Activity classes. Am using cursor
Iam retrieving data from the database and displaying it as a list, in the
I am fetching records from gae model using cursor() and with_cursor() logic as used

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.