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
 Grouping on Distinct Values

Author  Topic 

subrata.bauri
Starting Member

17 Posts

Posted - 2013-08-30 : 02:56:56
Dear Sir,

I want to get the summation of the amount column against all the distinct values of Description fields. May be the "Where" (applied on Tdate Column) Clause unable to contains all the Unique(Distinct) values from the single Column (Description).

Table Structure :
CREATE TABLE [dbo].[TransLine](
[TransID] [int] NULL,
[No] [int] NULL,
[Description] [varchar](50) NULL,
[Qty] [varchar](50) NULL,
[Rate] [decimal](18, 2) NULL,
[Amount] [decimal](18, 2) NULL,
[TDate] [datetime] NULL
) ON [PRIMARY]

GO

Sample data :
https://docs.google.com/file/d/0B774ux9ONqWNTUEtb0RNdFhzem8/edit?usp=sharing

Is It possible to get the same from a single Statement in SQL ?
Kindly reply...



**********************************************

It is not a slight thing when those so fresh from God love us.

**********************************************

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-30 : 03:05:10
Sounds like a simple GROUP BY based aggregate query. Can I ask what you tried yet?

http://www.w3schools.com/sql/sql_groupby.asp


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

subrata.bauri
Starting Member

17 Posts

Posted - 2013-08-30 : 03:15:15
Nice for reply from you.
If I use Group By with applying Where Clause on Tdate Column then it does not provide me all the distinct values from the Description Column which I have already stated here...


quote:
Originally posted by visakh16

Sounds like a simple GROUP BY based aggregate query. Can I ask what you tried yet?

http://www.w3schools.com/sql/sql_groupby.asp


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs






**********************************************

It is not a slight thing when those so fresh from God love us.

**********************************************
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-30 : 03:20:32
show us a data sample and explain what you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

subrata.bauri
Starting Member

17 Posts

Posted - 2013-08-30 : 04:03:04
Link provided for sample data in my post.

What I want that it should show all the time with it Distinct Description and their respective Amount summation where is "where" Clause can be applied.

quote:
Originally posted by visakh16

show us a data sample and explain what you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs






**********************************************

It is not a slight thing when those so fresh from God love us.

**********************************************
Go to Top of Page

subrata.bauri
Starting Member

17 Posts

Posted - 2013-08-30 : 07:15:01
I want to write a single query which will give me the three column as 1st column for Description, 2nd for Amount 3rd for Tdate.

1. Description capture all the the distinct values and
2. Amount field will show the accumulated sum for the respective Description, if the query finds any data otherwise zero.


Note : Where Clause unable to find the all distinct Description values.

**********************************************

It is not a slight thing when those so fresh from God love us.

**********************************************
Go to Top of Page
   

- Advertisement -