Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : programming pearls - The fastest algorithm can frequently be replaced by one that is almost as fast and much easier to understand.

Google
 
Web mainframegurukul.com

Welcome to the mainframegurukul forums.

You are currently viewing our mainframe forums as a guest which gives you limited access to view most discussions, articles. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support at admin@mainframegurukul.com


db2 query

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING
  View previous topic :: View next topic  
Author Message
thiyagucse
Member


Joined: 19 Feb 2006
Posts: 1

PostPosted: Sun Feb 19, 2006 10:35 pm    Post subject: db2 query Reply with quote

hai all
I am new to this group.How do i select a third max marks from table without using the subquery
Back to top
View user's profile Send private message

Rupesh.KOthari
Member


Joined: 16 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 11:37 am    Post subject: Reply with quote

HI,

Quote:
hai all
I am new to this group.How do i select a third max marks from table without using the subquery

Firstly Welcome to forum..... Very Happy

Is it possibel to select 3rd max without using Subquery??

Regards
Rupesh
_________________
------------------------
Thanks & Regards
Rupesh
-----------------------
Sun Shines Everywhere
Back to top
View user's profile Send private message
Kalicharan
Moderator


Joined: 08 Feb 2006
Posts: 31

PostPosted: Tue Feb 21, 2006 9:18 am    Post subject: selecting 3rd max marks from table without using subquery Reply with quote

Without Using SubQuery
********************

An equivalent query can also be code with a GROUP BY clause, but you
need to use a COUNT(DISTINCT x) operator to handle duplicates.
Here is the code

SELECT T1.MARK
FROM MARKSTABLE AS T1, MARKSTABLE AS T2
WHERE T1.MARK <= T2.MARK
GROUP BY T1.MARK
HAVING COUNT(DISTINCT T2.MARK) = 3

Using SubQuery
*************

SELECT T1.MARK
FROM MARKSTABLE AS T1
WHERE 3 = (SELECT COUNT(DISTINCT T2.MARK)
FROM MARKSTABLE AS T2
WHERE T1.MARK <= T2.MARK);

The performance of these two queries will vary with each SQL
implementation and with the available indexing.

Both the queries loops for n*n times where n is the total number of rows in the table.

Using TOP clause (works on SQL Server), is the effecient way of getting the nth max...
Back to top
View user's profile Send private message Send e-mail
sachin.kharade
Member


Joined: 28 Aug 2008
Posts: 1
Location: PUNE

PostPosted: Fri Aug 29, 2008 10:11 am    Post subject: Reply with quote

Hi,

can anyone tell me How I can decide whether to take comp or comp-3 fro a particular variable when writing program from scratch?

Regards
Sachin
kharade27@gmail.com
Back to top
View user's profile Send private message Send e-mail
Krishna
Site Admin


Joined: 27 Jan 2006
Posts: 929

PostPosted: Fri Aug 29, 2008 10:31 am    Post subject: Reply with quote

Sachin,

You need to start a new topic for this in the COBOL forum.. not here.

answer to your question -

COMP-3 - we can use if variable has the decimal positions.
For s9(1) and S9(5).. programmers suggest to use COMP-3 than COMP.
_________________
Regards,
Krishna
http://www.mainframegurukul.com
http://www.mainframetutorials.com
http://www.ibmmainframeguru.com
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Sort file by groups, keeping only the last group 7 TamiAZ 1070 Fri Oct 02, 2009 11:24 am
TamiAZ View latest post
No new posts What do you accomplish by GROUP BY ... HAVING clause? 1 Krishna 1215 Sun Mar 29, 2009 10:13 pm
Krishna View latest post
No new posts United Health group Interview ? 0 need@help 2548 Fri Mar 06, 2009 12:43 am
need@help View latest post
No new posts can i write a elementary item to group item. 1 mainframe5 1492 Tue Jun 17, 2008 1:47 pm
dbzTHEdinosauer View latest post
No new posts Why is Group move better than INITIALIZE verb? 1 NiceGuy 2314 Mon Nov 19, 2007 6:52 am
DavidatK View latest post
 



This widget requires Flash Player 9 or better








Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB