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.
Author |
Topic |
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2012-01-29 : 09:08:43
|
HalloI have follow problem..TabSalesitem....date.......town...cust....price1....price21....2011-02-10.....10....400........3........11....2011-03-25.....20....400........2........11....2011-04-06.....20....500........1........2a2...2011-02-15.....40....100........4........2a2...2011-09-16.....40....100........4........23....2011-03-29.....10....300........1........13....2011-07-31.....20....500........3........23....2011-07-10.....40....600........3........3RESULT: result is "select distinct" for "item"TabResultitem..frequency..nummonths..numtown..numcust..price1....price21...........3.............3...........2........2.........6...........4a2..........2.............2...........1........1.........8...........43...........3.............2...........3........3.........7...........6description:look at item for example "3"..frequency = is 3 (item is three count)nummonths = there are 2 months (march,july)numtown = there are 3 town(10,20,40)numcust = there are 3 customers (300.500.600),item a2 has 1 numcust(100)price1 = sum (1+3+3=7)price1 = sum (1+2+3=6)it is possible?big thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-29 : 14:22:06
|
[code]SELECT item,COUNT(date) AS frequency,COUNT(DISTINCT MONTH(date)) AS nummonths,COUNT(DISTINCT town) AS numtown,COUNT(DISTINCT cust) AS numcust,SUM(price1) AS price1,SUM(price2) AS price2FROM tableGROUP BY item[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2012-01-29 : 14:27:44
|
thanks visakh16my respect . . |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-29 : 14:35:16
|
welcometry and let us know the outcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2012-01-29 : 14:58:16
|
result?of course good. No°1I just switched "COUNT(date) AS frequency" on "COUNT(item) AS frequency"query is really simple, I need to learn |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2012-01-29 : 15:01:40
|
yesthanks visakh16 |
 |
|
|
|
|
|
|