Jump to content

Ms Sql Server Technology Discussions


9Pardhu

Recommended Posts

last weekend i had to help a friend in a sql timebound online interview.. dantlo

 

itemid   salescount   salesdate

1           10               2015-03-20

1           20              2015-02-27

2           5               2015-03-19

............

 

ila data untadhi,  for a given month print the top 5 items and salescount for that month   which are also in the top 5 of the previous month..

Select top 5 Itemid, Salesdate, Sum(Salescount)

From Tbl

group by Idemid, SalesDate

 

lasst clause ki Having lo agggregate vaadachu ankuntaa, but what is ans?

Link to comment
Share on other sites

Select top 5 Itemid, Salesdate, Sum(Salescount)

From Tbl

group by Idemid, SalesDate

 

lasst clause ki Having lo agggregate vaadachu ankuntaa, but what is ans?

 

dont print everything.. they should be also present in the top 5 of the previous month ,  MONTH()  function vaadochu  and -1 cheyochu  but january aithe december plus last year , DATEADD   DATEPART vaadi raasunde

 

group by simple ga unde i guess, nuvvu sum(salescount)  where MONTH(@givenmonth) = MONTH(salesdate)  AND DATEPART(yyyy,@givenmonth) = DATEPART(yyyy,salesdate)  kuda cheyalsi untadhi 

Link to comment
Share on other sites

dont print everything.. they should be also present in the top 5 of the previous month , MONTH() function vaadochu and -1 cheyochu but january aithe december plus last year , DATEADD DATEPART vaadi raasunde

group by simple ga unde i guess, nuvvu sum(salescount) where MONTH(@givenmonth) = MONTH(salesdate) AND DATEPART(yyyy,@givenmonth) = DATEPART(yyyy,salesdate) kuda cheyalsi untadhi

Where lo ivanni ekkadaa
Raastaav bhayya? Some other syntax ah sub query raayi I guess
Link to comment
Share on other sites

Face to Face interviews kiv ellinappudu... adiginaa SQl ki asn raakapotey best way to face it?

Daani related ga edo okati vaagi, I have worked on this topic earlier but on top of my head I am not able to recall it... raakapotey em chestam asalu man..
Link to comment
Share on other sites

dont print everything.. they should be also present in the top 5 of the previous month , MONTH() function vaadochu and -1 cheyochu but january aithe december plus last year , DATEADD DATEPART vaadi raasunde

group by simple ga unde i guess, nuvvu sum(salescount) where MONTH(@givenmonth) = MONTH(salesdate) AND DATEPART(yyyy,@givenmonth) = DATEPART(yyyy,salesdate) kuda cheyalsi untadhi


Man its very easy.. I am assuming you will pass which month you want to see..

there will be two queries.. one main query which calls present month data...

One sub query that calls previous months data..

Where you will relate both of them with an exists clause.. if that exists in the top 5 of previous months sub query result it will pull up in this month's main query.. I hope you got it.

I am not at a computer so couldn't write the code.. but this is very simple.. just looks for exists operator that's it man..
Link to comment
Share on other sites

Daani related ga edo okati vaagi, I have worked on this topic earlier but on top of my head I am not able to recall it... raakapotey em chestam asalu man..

hmmm adey chestunnaa... vaadu mari worst ga rayalsindeyy try cheyyi try cheyyi antaaduu live looo... enthaa expolain chesinaa vinaleduu

 

85% good interview but aah 15% is bothering me .. lets C

Link to comment
Share on other sites

hmmm adey chestunnaa... vaadu mari worst ga rayalsindeyy try cheyyi try cheyyi antaaduu live looo... enthaa expolain chesinaa vinaleduu

 

85% good interview but aah 15% is bothering me .. lets C

ok allah acha karega 

Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...