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
 Building Select statement...

Author  Topic 

vb89
Starting Member

9 Posts

Posted - 2008-10-10 : 15:07:14
I'm trying to create a select statement that takes the max of the ot.possession column and divides it by 2 and puts that value in the football_schedule table as the column quarter...Right now when i run the query there is no output, any ideas?


SELECT *
FROM customer_data.cd_football_game_scoring t, customer_data.cd_football_schedule s
WHERE s.quarter =(select(max(count(t.ot_possession) /2)) from customer_data.cd_football_game_scoring t group by t.game_code)
AND t.game_code = 814533
AND s.game_code = 814533
AND t.scored = 'Y'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-10 : 15:28:31
Does the following return the value you want to use:

select(max(count(t.ot_possession) /2)) from customer_data.cd_football_game_scoring t group by t.game_code



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

vb89
Starting Member

9 Posts

Posted - 2008-10-10 : 15:45:54
In a nutshell, yes it does
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-10 : 15:53:44
SELECT Column1, Column2, ..., s.quarter = (that query)
FROM customer_data.cd_football_game_scoring t, customer_data.cd_football_schedule s
WHERE t.game_code = 814533
AND s.game_code = 814533
AND t.scored = 'Y'


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

vb89
Starting Member

9 Posts

Posted - 2008-10-10 : 16:12:09
I went ahead and did that...but when i run the query it says 'from keyword not found where expected'
i wrote the code like this...

column names...,s.quarter = select(max(count(t.ot_possession))/2) from customer_data.cd_football_game_scoring t group by t.game_code)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-10 : 16:41:45
I think you are missing parenthesis aroun "that query".

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -