Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Request

Author  Topic 

ozsql
Starting Member

14 Posts

Posted - 2009-09-17 : 05:01:40
Hi Guys,

This is my first project can anyone help me by providing SQL query, how to generate below questions. They are three questions a,b and c.

Tblconsignment
Job_no, job_type, book_date, cust_code, depot, revenue, manifestexpenses

A) No of Consignments in the table. If NULL represent as ‘unknown’.
B) Total revenue on consignments
C) Total revenue per consignment


Thanks,

Roman

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-17 : 05:02:57
A) use count(*)
B) use SUM()
C) use SUM() + GROUP BY


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-17 : 05:03:46
What have you tried so far?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-17 : 06:05:14
A)

SELECT count(*), IsNull(Job_Type, 'Unknown')
FROM TblConsignment

GROUP BY Job_Type

-- Will show how many consignements there has been for each job_type, and null values will be counted under header 'Unknown'.

B) and C) as khtan said, use SUM() on B), and SUM() ... GROUP BY() on C.

Need any further help then feel free to ask.

I would use a temporary table for everything ever
Go to Top of Page

ozsql
Starting Member

14 Posts

Posted - 2009-09-17 : 06:36:10
Thanks Very Much guys !!!!!!
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-17 : 07:04:35
Always feel free to ask for help.

I would use a temporary table for everything ever
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-17 : 08:17:12
<<
I would use a temporary table for everything ever
>>

Why?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-09-17 : 08:24:27
quote:
Originally posted by madhivanan

<<
I would use a temporary table for everything ever
>>

Why?

Madhivanan

Failing to plan is Planning to fail



So he can format it in the front end? [ /fail at humor]

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-17 : 08:39:07
quote:
Originally posted by madhivanan

<<
I would use a temporary table for everything ever
>>

Why?

Madhivanan

Failing to plan is Planning to fail



that's just winterh's signature line. It is not a reply to OP's question


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-17 : 08:40:30
quote:
Originally posted by DonAtWork

quote:
Originally posted by madhivanan

<<
I would use a temporary table for everything ever
>>

Why?

Madhivanan

Failing to plan is Planning to fail



So he can format it in the front end? [ /fail at humor]

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-17 : 08:41:00
quote:
Originally posted by khtan

quote:
Originally posted by madhivanan

<<
I would use a temporary table for everything ever
>>

Why?

Madhivanan

Failing to plan is Planning to fail



that's just winterh's signature line. It is not a reply to OP's question


KH
[spoiler]Time is always against us[/spoiler]




Ok. Thanks

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-17 : 09:02:36
It was a quote taken from someone I know. I feel I should change it now. lol. Thanks guys :(

I would use a temporary table for everything ever
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-17 : 09:04:35
better?

[ /fail at humor]
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-09-17 : 10:58:55
I have been quoted! yay me.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-18 : 07:04:29
:)

[ /fail at humor]
Go to Top of Page
   

- Advertisement -