Click here to Skip to main content
15,891,316 members
Home / Discussions / Database
   

Database

 
QuestionHidden tables Pin
mistryshailesh29-Jun-09 21:52
mistryshailesh29-Jun-09 21:52 
AnswerRe: Hidden tables Pin
Niladri_Biswas29-Jun-09 23:10
Niladri_Biswas29-Jun-09 23:10 
QuestionOLEDB network failure recovery problem. Pin
CherezZaboro29-Jun-09 6:57
CherezZaboro29-Jun-09 6:57 
QuestionEncryptbyKey VARCHAR(50) Pin
Saamir29-Jun-09 6:42
Saamir29-Jun-09 6:42 
QuestionMy Sql Query Help Pin
Hulicat29-Jun-09 6:26
Hulicat29-Jun-09 6:26 
AnswerRe: My Sql Query Help Pin
Niladri_Biswas29-Jun-09 6:54
Niladri_Biswas29-Jun-09 6:54 
GeneralRe: My Sql Query Help Pin
Hulicat29-Jun-09 11:23
Hulicat29-Jun-09 11:23 
GeneralRe: My Sql Query Help [modified] Pin
Niladri_Biswas29-Jun-09 19:33
Niladri_Biswas29-Jun-09 19:33 
I am assuming certain things.

I have created both the tables and has inserted certain values. Please look into it whether you also have the same values or not!

tblSpend

COLUMN NAME			DATATYPE	
-----------			-------
SPENDACCOUNT			int	
FROMCODE			int	
KEYWORD				varchar(50)	
KWTYPE				int	
CLICKS				int	
SPEND				int	


Values in tblSpend are

101	1	KeyWord1	1	1	10
102	2	KeyWord2	1	10	11
103	3	KeyWord3	2	21	15
104	4	KeyWord4	3	22	16
105	5	KeyWord5	5	11	11
106	6	KeyWord6	2	33	12
107	7	KeyWord7	1	111	11
108	8	KeyWord8	2	22	2
109	9	KeyWord9	1	1	1
110	10	KeyWord10	1	2	3



tblRev

COLUMN NAME			DATATYPE	
-----------			-------
NEWACCOUNTS			int
GROSS				int
REFUNDS				int
NET				int
TRANS				int
FROMCODE			int


Values in tblRev are

1	10	20	10	10	1
2	20	30	10	20	2
3	30	40	15	25	3
4	40	50	45	5	4
5	50	100	50	50	5
6	60	400	200	200	6
7	70	100	100	0	7
8	70	100	50	50	7
6	111	300	120	180	6



The Query is

SELECT 

		S.SPENDACCOUNT, S.KEYWORD, 
		S.KWTYPE,S.CLICKS,S.SPEND,

		D.FROMCODE,D.TRANS,D.NEWACCOUNTS,
		D.GROSS,D.REFUNDS,D.NET

	FROM (

				SELECT 
						T.FROMCODE,
						SUM (R.TRANS) TRANS,
						SUM (R.NEWACCOUNTS) NEWACCOUNTS,	
						SUM (R.GROSS) GROSS,	
						SUM (R.REFUNDS) REFUNDS,	
						SUM (R.NET) NET

				FROM TBLSPEND T, TBLREV R 
				WHERE 
						T.FROMCODE= R.FROMCODE

				GROUP BY T.FROMCODE 

			) D, TBLSPEND S

WHERE  S.FROMCODE   = D.FROMCODE 


OUTPUT:

101	KeyWord1	1	1	10	1	1	10	20	10	10
102	KeyWord2	1	10	11	2	2	20	30	10	20
103	KeyWord3	2	21	15	3	3	30	40	15	25
104	KeyWord4	3	22	16	4	4	40	50	45	5
105	KeyWord5	5	11	11	5	5	50	100	50	50
106	KeyWord6	2	33	12	6	12	171	700	320	380
107	KeyWord7	1	111	11	7	15	140	200	150	50



Hope this helps
Smile | :)

Niladri Biswas

modified on Tuesday, June 30, 2009 4:26 AM

GeneralRe: My Sql Query Help Pin
Hulicat1-Jul-09 7:06
Hulicat1-Jul-09 7:06 
AnswerRe: My Sql Query Help Pin
smcnulty200029-Jun-09 21:19
smcnulty200029-Jun-09 21:19 
GeneralRe: My Sql Query Help Pin
Hulicat30-Jun-09 3:59
Hulicat30-Jun-09 3:59 
GeneralRe: My Sql Query Help Pin
Hulicat30-Jun-09 7:30
Hulicat30-Jun-09 7:30 
QuestionHow to Optimize DbTransactions (C#) with SQLServer ? Pin
kadaoui el mehdi29-Jun-09 4:55
kadaoui el mehdi29-Jun-09 4:55 
AnswerRe: How to Optimize DbTransactions (C#) with SQLServer ? Pin
Enver Maroshi29-Jun-09 7:10
Enver Maroshi29-Jun-09 7:10 
GeneralRe: How to Optimize DbTransactions (C#) with SQLServer ? Pin
kadaoui el mehdi29-Jun-09 7:32
kadaoui el mehdi29-Jun-09 7:32 
AnswerRe: How to Optimize DbTransactions (C#) with SQLServer ? Pin
Niladri_Biswas30-Jun-09 5:50
Niladri_Biswas30-Jun-09 5:50 
Questionon full-text-search Pin
leone29-Jun-09 4:47
leone29-Jun-09 4:47 
Questionho to retrieve a list of dependants Pin
Anoop Brijmohun29-Jun-09 2:59
Anoop Brijmohun29-Jun-09 2:59 
AnswerRe: ho to retrieve a list of dependants [modified] Pin
Niladri_Biswas29-Jun-09 23:59
Niladri_Biswas29-Jun-09 23:59 
GeneralRe: ho to retrieve a list of dependants Pin
Anoop Brijmohun5-Jul-09 20:16
Anoop Brijmohun5-Jul-09 20:16 
QuestionConvert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 0:31
professionalVimalsoft(Pty) Ltd29-Jun-09 0:31 
AnswerRe: Convert String and Sort the the Intergers in a String ASC Pin
Aman Bhullar29-Jun-09 2:20
Aman Bhullar29-Jun-09 2:20 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 2:25
professionalVimalsoft(Pty) Ltd29-Jun-09 2:25 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Aman Bhullar29-Jun-09 3:06
Aman Bhullar29-Jun-09 3:06 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 3:21
professionalVimalsoft(Pty) Ltd29-Jun-09 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.