Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SQL query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
shri_shant

New User


Joined: 26 Oct 2005
Posts: 16

PostPosted: Fri Dec 16, 2005 3:41 pm    Post subject: SQL query
Reply with quote

I am having table(p) as follows and output given in table below that what is query to get that output.........?


p# pname color weight city

p1 Nut red 12 london
p2 Bolt green 17 paris
p3 Screw Blue 17 Rome
p4 Screw red 14 London
p5 Cam blue 12 paris
p6 Cog red 19 London


Output table is

weight pname

12 cam
nut
14 screw
17 bolt
screw
19 cog


Thanks in advance
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 16, 2005 5:19 pm    Post subject: Re: SQL query
Reply with quote

Code:
SELECT PNAME, WEIGHT FROM <TABLE-NAME> WHERE 1 = 1                             
GROUP BY PNAME, WEIGHT HAVING COUNT(WEIGHT)>1; 


Try this & let me know the results....

Regards,

Priyesh.
Back to top
View user's profile Send private message
akashs

New User


Joined: 24 Nov 2005
Posts: 49
Location: chennai

PostPosted: Fri Dec 16, 2005 5:28 pm    Post subject: Re: SQL query
Reply with quote

priyesh ,
iam unable to understand ur query ...wht is 1=1.expalin it plz...

regards,
akash
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 16, 2005 5:36 pm    Post subject: Re: SQL query
Reply with quote

Quote:
wht is 1=1.expalin it plz...


It means always... icon_biggrin.gif

Regards,

Priyesh.
Back to top
View user's profile Send private message
reachsenthilnathan

New User


Joined: 20 Nov 2005
Posts: 15

PostPosted: Fri Dec 16, 2005 6:56 pm    Post subject:
Reply with quote

1=1 Is always true. It is required as you need to put a where condition in the query which has group by and having.

Please correct me if i am wrong.

With Regards,
Senthil Nathan.R
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 0 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us