SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


help for select statement


help for select statement

Author
Message
ssurekha2000
ssurekha2000
SSC-Addicted
SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)

Group: General Forum Members
Points: 423 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
Lowell
Lowell
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73515 Visits: 40973
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
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search