sql server 2005 - SQL: Select all rows that meet a condition if that condition is met, but only a certain nuber rows if it isn't -
I have a requirement for a SQL Server 2005 query that I need to write and I have to complete it How to be completed I will simplify it a little bit, but the essence is that if a customer is not at all exactly at any given date, then I have to choose from the customer's most recent bills. But if they have billions after the cutoff date, just show them to any of those bills.
Therefore, if my cutoff date is January 1, 2010 and I have the data as follows:
ClaimID ClientID billing date 1 March 12, 2010 2 June 1, 3 , 2010 3 January 1, 2008 4 February 1 9, 2011 5 May 19, 2005 6 November 2, 20, 2005 7 October 2, 2009 8 3 January 4, 1999 9 July, 8, 1997 10 May 3 7, 2010 11 3 August 6, 1999 12 May 24, 2000 13 April 4, 2005 14 4 March 9, 2009 15 December 4, 2007 16 December 4, 19, 1998 17 June 4, 2006 < / Pre> Then I want to select:
Clemice Cleant ID Belith 1 1 Mar 12, 2010 2 June 1, 2010 4 February 1 9, 2011 6 November 2, 20, 2005 7 October 2, 2009 10 May 3, 2010 14 4 March 9, 2009 15 December 4, 2007 17 June 4, 2006 Anyone have any ideas? Billing
-
BillingDate . -
For each client, output dates that are:
-
More than the cut-off date, < / P>
-
3 are ranked highest.
query:
; In the form of ranking (SELECT *, rownum = ROW_NUMBER ()) (by Billing ID: Customer ID Ordered Billing by DACC) Click Claims, ClientId, BillDate was given place from where Billing Billing & gt; @ Cutoffdate or color between 1 and 3
Comments
Post a Comment