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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:10:45+00:00 2026-06-07T00:10:45+00:00

I’ve table like this VB(name char(25), amount numeric(6), ret_date date): Name Amount Ret_date —-

  • 0

I’ve table like this VB(name char(25), amount numeric(6), ret_date date):

Name  Amount  Ret_date
----  ------  --------
abc    500    2011-01-21
def    200    2011-01-20
ghi   1000    
xyz    800    2011-01-22
def    200    
def    400    2011-02-01
pqr   2100    2011-02-12  
abc   3000    
abc   4100
xyz    700    2011-01-22

What I wanted is (count based on ret_date for distinct names: total count, return count, pending count):

Name    tc  rc  pc 
abc     3   1   2 
def     3   2   1 
xyz     2   2   0 
ghi     1   0   1 
pqr     1   1   0

I’ve tried the following queries, nothing worked!

SELECT vb.name, COUNT(*) tc, r.rc, p.pc FROM vb, ;
 (SELECT name, COUNT(*) rc FROM vb WHERE ret_date != {} group BY name) r, ;
 (SELECT name, COUNT(*) pc FROM vb WHERE ret_date = {} group BY name) p ;
 GROUP BY vb.name ORDER BY tc desc
SELECT vb.name, COUNT(*) tc, r.rc, p.pc FROM vb ;
  LEFT JOIN (select name, COUNT(*) rc FROM vb WHERE ret_date != {} group BY name) r ON r.name = vb.name ;
  LEFT JOIN (select name, COUNT(*) pc FROM vb WHERE ret_date = {} group BY name) p ON p.name = vb.name ;
  GROUP BY vb.name
SELECT vb.name, COUNT(*) tc, r.rc, p.pc FROM vb ;
  LEFT JOIN (select r.name, COUNT(*) rc FROM vb r WHERE ret_date != {} group BY name) r ON r.name = vb.name ;
  LEFT JOIN (select p.name, COUNT(*) pc FROM vb p WHERE ret_date = {} group BY name) p ON p.name = vb.name ;
  GROUP BY vb.name

I was able to get the count with 3 separate queries (total count, count for ret_date = {}, ret_date != {}) but can’t get at the same time using a single query. Please help me get the desired output. I am new to SQL and can understand the basics but things like joins, subqueries are still difficult to understand! It would be helpful if you could explain what your query does.

Note: I’m using MS Visual Foxpro 9.0 (Windows 7). { } is a notation used to express emptiness for date type in Foxpro and != is not equal to operator.

Thanks a lot.

  • 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-07T00:10:46+00:00Added an answer on June 7, 2026 at 12:10 am
    SELECT name, COUNT(DISTINCT name) as uc, COUNT(*) as tc, SUM(IF(ret_date IS NULL, 0, 1)) as rc, SUM(IF(ret_date IS NOT NULL, 0, 1)) as pc
    FROM vb
    GROUP BY name;
    

    I don’t have access to Foxpro, but this works in MySQL. Hopefully you can tweak it to suit your purposes.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.