We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Related to my other Query Question

yankel1
yankel1 asked
on
Medium Priority
248 Views
Last Modified: 2013-11-27
I wan't the count only since the last approved one let say 11/1/2008 it was decliend, 12/1/2008 it was approved, 1/1/2009 Declined, 2/1/2009 Declined again. I want the the number 2.
Comment
Watch Question

since u didnt give us any detail of your table, i would expect the following

select count(*) from table where status = 'decline' and time > (select max(time)  from table where status = 'approve')

adjust it according to your needs
this?
select count(*) from CreditCardsResponse where Not Approved and ProcessDateTime > (select max(ProcessDateTime)  from CreditCardsResponse where Approved)

Open in new window

Author

Commented:
ok thats good!
but I need for each MasterID the count
select a.MasterID, count(*) from CreditCardsResponse a, (select MasterID,max(ProcessDateTime) as maxtime from CreditCardsResponse where Approved group by MasterID) b  where Not a.Approved and a.ProcessDateTime > b.maxtime and a.MasterID = b.MasterID

Author

Commented:
I get this error

You tried to execute a query that does not include the specified expression as part of an aggregate function or grouping.
oops

select a.MasterID, count(a.ProcessDateTime) from CreditCardsResponse a, (select MasterID,max(ProcessDateTime) as maxtime from CreditCardsResponse where Approved group by MasterID) b  where Not a.Approved and a.ProcessDateTime > b.maxtime and a.MasterID = b.MasterID

Author

Commented:
Same error :(
this works right?

select MasterID,max(ProcessDateTime) as maxtime from CreditCardsResponse where Approved group by MasterID

Author

Commented:
yes this works

I'm attaching the table I'm using
Sample.mdb
select a.MasterID, count(a.ProcessDateTime) from CreditCardsResponse a, (select MasterID,max(ProcessDateTime) as maxtime from CreditCardsResponse where Approved group by MasterID) b  where Not a.Approved and a.ProcessDateTime > b.maxtime and a.MasterID = b.MasterID group by a.MasterID

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That work's great!!!

Author

Commented:
oopes one thing I forgot

I want to count just once per month, if it was declined twice in one month it should count it as one
that's not easy for me. but I think you can do it by first do some data massaging to get rid of 'duplicated' decline within the same month and then just use  the query above.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.