Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
tblCompOff

SQL
Compofid  location    tid    compdate   userid    totdays
  1       consite     4     12-12-12      2         1
  2       consite     5     12-12-13      2         1
  3       cofsite     6     12-12-14      2         1


In my select statement i want to show like

SQL
location    userid    totdays
 consite       2        2
 cofsite       2        1


Is it possible how to proceed....,?
Posted
Updated 3-Jan-13 1:59am
v2

SQL
select location, userid, sum(totdays) as totdays from tablename group by location, userid
 
Share this answer
 
v2
Comments
URVISH_SUTHAR1 3-Jan-13 8:06am    
yup above query should work as expected
SQL
select location, userid,SUM(totdays) as totdays from tablename group by location,userid
 
Share this answer
 
In essence, yes it is possible, but exactly how depends on a number of factors.
Firstly there is your selection criteria - or how you pick which records you want to retrieve, and which you don't.
Secondly, it depends on how you store your information. If you want to select based on a date for example, then if you store your "compdate" field as a string it is difficult to do.

Assuming that you r fields are sensibly stored, and your selection criterisa is "on or after 13th december last year" then
SQL
SELECT location, userid, totdays FROM tblCompOff WHERE compdate >= '2012-12-13'
would do it. The WHERE clause specifies the selection criteria.
 
Share this answer
 
Comments
Jibesh 3-Jan-13 8:09am    
This solution doesnt fit OPs request. he wann sum of totdays for the location, I think you didnt noticed that.
OriginalGriff 3-Jan-13 8:15am    
Oops! You are right I missed that :O
In my defence, I was looking at the unformatted version - but Zoltan has posted the correct version, and he was looking at the same... I'll have to blame a lack of caffiene! :laugh:
Jibesh 3-Jan-13 8:24am    
You Bet. Even I thought of the same answer but when it displayed formatted it clears e.thing. :)
sariqkhan 4-Jan-13 14:55pm    
http://www.codeproject.com/Questions/521783/howplustoplustransferplustheplustextplusfromplusdy
can you help me sir
sariqkhan 4-Jan-13 14:55pm    
http://www.codeproject.com/Questions/521783/howplustoplustransferplustheplustextplusfromplusdy
can you help me sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900