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
 Need help on the query

Author  Topic 

Maddy_30
Starting Member

2 Posts

Posted - 2014-05-26 : 05:04:32
I have a table with the following data
TicketNum(VARCHAR) Amount(DECIMAl)
10000000008 13.5
10000000009 10
10000000012 10.78
10000000233 0.23

I need the count of Ticket numbers having amount less than $30
Also the amount should be integers .

sample:

amount Ticket_Count
10 2
13 1

This is the query i have come so far

select CAST(Amount as Int) as Amt ,CAST(count(ticketNumber)as INT) as count
from tablename where Amount < 50
group by Amount

Ouput I get is :

amount Ticket_Count
10 1
10 1
13 1

the ticket count should be 2 for $10 . Please help how can I get that.









Maddy

Tusharp86
Starting Member

9 Posts

Posted - 2014-05-26 : 05:19:51
select CAST(Amount as Int) as Amt ,CAST(count(ticketNumber)as INT) as count
from tic where Amount < 50
group by CAST(Amount as Int)
Go to Top of Page

GouravSaxena1987
Starting Member

23 Posts

Posted - 2014-05-26 : 12:45:55
Maddy,

Solution given by Tusharp should work!!

Regards,
Gourav Saxena
Data Warehouse Counsultant
GouravSaxena1987@gmail.com
Go to Top of Page

Maddy_30
Starting Member

2 Posts

Posted - 2014-05-26 : 22:19:10
Hey, Thanks it worked !!!

Maddy
Go to Top of Page
   

- Advertisement -