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
 

 

Need sql query to display Subscriber ID

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

New User


Joined: 07 May 2005
Posts: 22

PostPosted: Thu Oct 04, 2007 3:01 pm    Post subject: Need sql query to display Subscriber ID
Reply with quote

Hi Friends,

i need a SQL query for below question

A table SUBS_BILL_PYMT stores monthly bill payment information from subscribers. It always stores one month’s worth data.
Display subscriber IDs who paid bills more than once in a month on at least two different dates.

SUBSCRIBER_ID DATE_BILL_PAID BILL_AMT
S1 01/02/2007 100
S1 01/02/2007 250
S2 01/10/2007 50
S2 01/13/2007 505
S3 01/05/2007 600
S5 01/11/2007 50
S5 01/16/2007 505
S5 01/16/2007 505

Going by the above requirement, output should display
Subscriber ID
--------------------
S2
S5

need a query for the same.

regards
murali
Back to top
View user's profile Send private message

agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Thu Oct 04, 2007 3:25 pm    Post subject:
Reply with quote

select SUBSCRIBER_ID, count(*) from SUBS_BILL_PYMT group by SUBSCRIBER_ID having count(*) > 1

This will print the occurence also in the result. If you dont want that count column then declare a view with above shown query and select SUBSCRIBER_ID from it.
I don't say this is the best answer for the question but this is what it came to my mind instantly.
Back to top
View user's profile Send private message
murali_andaluri
Currently Banned

New User


Joined: 07 May 2005
Posts: 22

PostPosted: Thu Oct 04, 2007 3:37 pm    Post subject: Reply to: i need sql query
Reply with quote

Thank you very much abhijit.
Back to top
View user's profile Send private message
murali_andaluri
Currently Banned

New User


Joined: 07 May 2005
Posts: 22

PostPosted: Thu Oct 04, 2007 3:49 pm    Post subject: Reply to: i need sql query
Reply with quote

Hi Abhijit,

this query will display the subscriber IDs who paid bills more than once in a month, but we need subcribers IDs on at least two different dates.

for example your query will give the subscriber IDs those who paid more than once in a day also but we need on different dates.

regards
murali
Back to top
View user's profile Send private message
nuthan

Active User


Joined: 26 Sep 2005
Posts: 146
Location: Bangalore

PostPosted: Thu Oct 04, 2007 5:54 pm    Post subject:
Reply with quote

Try this out

select SUBSCRIBER_ID, count(*) from SUBS_BILL_PYMT group by SUBSCRIBER_ID having count(DISNTINCT DATE_BILL) > 1
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 2 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 Display ZEDLMSG without Pressing F1 &... anandgbe CLIST & REXX 8 Thu Dec 15, 2016 4:20 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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