• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

TSQL Query


HI, Below is my sample data from a table. I just want
to get those id's where the answer to qid 82 is greater
than the answer given to qid 1306.

   Can any one give me that TSQL script please ?

Thanks



id QID     Answer Startdate
         
 1  1306    2018   31/03/2009
 1  82      3099   30/09/2007
0
gvamsimba
Asked:
gvamsimba
2 Solutions
 
sarabhaiCommented:
SELECT id  FROM TABLE
WHERE id > 82  AND id = 1306
0
 
Ephraim WangoyaCommented:

select A.*
from Table1 A
inner join  table1 B on B.ID = A.ID
where A.QID = 82
and B.QID = 1306
and A.Answer > B.Answer
0
 
sarabhaiCommented:
SELECT id  FROM TABLE
WHERE qid > 82  AND qid = 1306
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
Imran Javed ZiaCommented:
Hi,
Please try following:

select a.id,  a.QID, a.Answer, a.Startdate
From Table a
      Inner Join Table on a.Answer>b.Answer  
Where a.Answer = 82

Thanks
0
 
Paul_Harris_FusionCommented:
I don't think your statement of the problem makes sense.....and as a result, I don't think the solutions do either.

arabhai : will always return the id from qid = 1306
ewangoya: will always return the row with qid = 83 unless the values for answer are changed in which case it may return nothing - these are the only two possibilities

Can I respectfully suggest you check your statement of the requirements?
0
 
Ephraim WangoyaCommented:

The solution should be generally of the form

select A.*
from Table1 A
inner join  table1 B on B.ID = A.ID
where A.Answer > B.Answer

But the author specified record values hence the inclusion, How do we know if there are no multiple QID values?
0
 
anillucky31Commented:

this is solution for your problem. I am assuming that your table name is question

if you want to get just id then use  this

SELECT a.Id FROM Question a
 INNER JOIN Question b ON a.Id = b.Id WHERE a.QId = 82 AND b.Qid = 1306
 AND a.answer > b.answer
 
if you want to get the rows then use this
 SELECT * FROM Question WHERE Id IN   (
 SELECT a.Id FROM Question a
 INNER JOIN Question b ON a.Id = b.Id WHERE a.QId = 82 AND b.Qid = 1306
 AND a.answer > b.answer)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now