Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

help for select statement Expand / Collapse
Author
Message
Posted Tuesday, June 21, 2011 5:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, May 6, 2014 5:04 AM
Points: 79, Visits: 207
here is a the entire details of the table with the expected output

Table name= Billdeatils

billno customer basicamt ta date location

1005 200 10
1008 500 15
1003 800 20
2015 1000 10
2015 300 12
1008 200 18
1003 1500 15
1005 2000 16
2015 400 20
2010 500 50
1003 600 25
1000 300 20

toral record count =12

query for getting the below output

1) count (disctinct billno) = 7
2) sum (basicamt + ta) of all 12 records

3) for each bill i need i need count & sum
eg billno =1005

count(billno) where billno =1005 shld give 2
sum (basicamt + ta) where billno =1005 shld give 2226


4) details of each bill
eg billno =1005

1005 200 10
1005 2000 16

the below is the quer y but

SELECT DISTINCT billno,(SELECT COUNT(DISTINCT billno) FROM billdetails) AS ccount,
(SELECT sum(basicamt+ta) FROM billdetails) AS amt,
(SELECT COUNT( billno) FROM billdetails where billno=1005) AS paycount,
(SELECT sum(basicamt+ta) FROM billdetails where billno=1005)
AS payamt,
(SELECT * FROM billdetails where billno=1005)
FROM billdetails
Post #1128922
Posted Tuesday, June 21, 2011 6:02 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:11 PM
Points: 12,876, Visits: 31,789
nice job on posting details so we can follow along...but is there a question in there somewhere? is this related to compact edition(the forum you posted) or a specific version of SQL?

this looks a little bit like homework...what have you tried so far?


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1128923
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse