How to get any three rows of particular date in SQL Server -
i stucking in 1 sql query.
my table format below:
acct# admitdate dos chargeamount 12366 2011-12-07 00:00:00.000 2011-12-15 00:00:00.000 25.00 12366 2011-12-07 00:00:00.000 2011-12-16 00:00:00.000 30.00 12366 2011-12-07 00:00:00.000 2011-12-17 00:00:00.000 55.00 12366 2011-12-07 00:00:00.000 2011-12-18 00:00:00.000 48.00 12366 2011-12-07 00:00:00.000 2011-12-19 00:00:00.000 25.00 12366 2012-01-08 00:00:00.000 2012-01-08 00:00:00.000 58.00 12366 2012-01-08 00:00:00.000 2012-01-09 00:00:00.000 46.00 12366 2012-01-08 00:00:00.000 2012-01-10 00:00:00.000 90.00 12366 2012-01-08 00:00:00.000 2012-01-11 00:00:00.000 52.00 12366 2012-01-08 00:00:00.000 2012-01-12 00:00:00.000 95.00 12366 2012-01-08 00:00:00.000 2012-01-13 00:00:00.000 53.20i want top 3 dos 1 admit date , sum of chargeamount. other dos should neglact. i have no thought how this. want below desired output.
acct# admitdate chargeamount 12366 2011-12-07 00:00:00.000 128.00 12366 2012-01-08 00:00:00.000 200.00only 2011-12-17 2011-12-19 admit date 2011-12-07 need sum , same other admit date. if have sql query please share me.
thanks in advance
try:
select top 3 acct, admitdate, sum(chargeamount) yourtable grouping acct, admitdate
edit
select acct, admitdate, sum(chargeamount) , rank() on (partition admitdate order admitdate desc) yourtable grouping acct, admitdate
sql-server-2008 sql-server-2005
No comments:
Post a Comment