Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:59+00:00 2026-06-12T02:28:59+00:00

In the Enrollment_Changes table, the phone model listed is the phone the subscriber changed

  • 0

In the Enrollment_Changes table, the phone model listed is the phone the subscriber changed FROM on that date.

If there is no subsequent change on Enrollment_Changes, the phone the subscriber changed TO is listed on the P_Enrollment table

For example, subscriber 12345678 enrolled on 1/5/2011 with a RAZR. On 11/1/2011 he changed FROM the RAZR. You can see what he changed TO with the next transaction on Enrollment_Changes on 05/19/2012.

How would you find the Count of subs that first enrolled with the iPhone 3?

Here is the code I have for creating the tables

Create Tables: TBL 1

USE [Test2]
GO

/****** Object:  Table [dbo].[P_ENROLLMENT]    ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[P_ENROLLMENT](
    [Subid ] [float] NULL,
    [Enrollment_Date] [datetime] NULL,
    [Channel] [nvarchar](255) NULL,
    [Region] [nvarchar](255) NULL,
    [Active_Status] [float] NULL,
    [Drop_Date] [datetime] NULL,
    [Phone_Model] [nvarchar](255) NULL
) ON [PRIMARY]

GO

TBL 2

USE [Test2]
GO

/****** Object:  Table [dbo].[ENROLLMENT_CHANGES]     ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[ENROLLMENT_CHANGES](
    [Subid] [float] NULL,
    [Cdate] [datetime] NULL,
    [Phone_Model] [nvarchar](255) NULL
) ON [PRIMARY]

GO

Insert TBL1

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12345678, '2011-01-05 00:00:00', 'Retail', 'Southeast', 1, NULL, 'iPhone 4');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12346178, '2011-03-13 00:00:00', 'Indirect Dealers', 'West', 1, NULL, 'HTC Hero');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12346679, '2011-05-19 00:00:00', 'Indirect Dealers', 'Southeast', 0, '2012-03-15 00:00:00', 'Droid 2');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12347190, '2011-07-25 00:00:00', 'Retail', 'Northeast', 0, '2012-05-21 00:00:00', 'iPhone 4');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12347701, '2011-08-14 00:00:00', 'Indirect Dealers', 'West', 1, NULL, 'HTC Hero');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12348212, '2011-09-30 00:00:00', 'Retail', 'West', 1, NULL, 'Droid 2');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12348723, '2011-10-20 00:00:00', 'Retail', 'Southeast', 1, NULL, 'Southeast');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12349234, '2012-01-06 00:00:00', 'Indirect Dealers', 'West', 0, '2012-02-14 00:00:00', 'West');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12349745, '2012-01-26 00:00:00', 'Retail', 'Northeast', 0, '2012-04-15 00:00:00', 'HTC Hero');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12350256, '2012-02-11 00:00:00', 'Retail', 'Southeast', 1, NULL, 'iPhone 4');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12350767, '2012-03-02 00:00:00', 'Indirect Dealers', 'West', 1, NULL, 'Sidekick');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12351278, '2012-04-18 00:00:00', 'Retail', 'Midwest', 1, NULL, 'iPhone 3');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12351789, '2012-05-08 00:00:00', 'Indirect Dealers', 'West', 0, '2012-07-04 00:00:00', 'iPhone 3');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12352300, '2012-06-24 00:00:00', 'Retail', 'Midwest', 1, NULL, 'Droid 2');

INSERT INTO [P_ENROLLMENT]([Subid ], [Enrollment_Date], [Channel], [Region], [Active_Status], [Drop_Date], [Phone_Model]) 
    VALUES(12352811, '2012-06-25 00:00:00', 'Retail', 'Southeast', 1, NULL, 'Sidekick');

Insert TBL2

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12345678, '2011-11-01 00:00:00', 'RAZR');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12346178, '2012-01-07 00:00:00', 'HTC Hero');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12348723, '2012-01-28 00:00:00', 'RAZR');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12350256, '2012-02-21 00:00:00', 'Blackberry Bold');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12349745, '2012-05-05 00:00:00', 'HTC Hero');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12345678, '2012-05-19 00:00:00', 'Palm Pre');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12347190, '2012-05-20 00:00:00', 'HTC Hero');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12350256, '2012-05-21 00:00:00', 'Blackberry Bold');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12349234, '2012-06-04 00:00:00', 'Palm Pre');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12346178, '2012-06-05 00:00:00', 'iPhone 3');

INSERT INTO [ENROLLMENT_CHANGES]([Subid], [Cdate], [Phone_Model]) 
    VALUES(12350767, '2012-06-10 00:00:00', 'iPhone 3');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:29:01+00:00Added an answer on June 12, 2026 at 2:29 am

    For the count

    select COUNT(*) Total
    from
    (
        select e.*,
            rn = row_number() over (partition by e.subid order by c.cdate desc),
            first_model = coalesce(c.phone_model, e.phone_model)
        from [P_ENROLLMENT] e
        left join [ENROLLMENT_CHANGES] c on c.subid = e.subid
    ) x
    where rn=1 and first_model = 'iPhone 3'
    

    For all the records

    select *
    from
    (
        select e.*,
            rn = row_number() over (partition by e.subid order by c.cdate desc),
            first_model = coalesce(c.phone_model, e.phone_model)
        from [P_ENROLLMENT] e
        left join [ENROLLMENT_CHANGES] c on c.subid = e.subid
    ) x
    where rn=1 and first_model = 'iPhone 3'
    order by subid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a temporary table that I need to populate with the records
Take the following simple object model for example: class Course has_many :enrollments has_many :students,
I am using this query to calculate percent change of Enrollment total from current
So I have a table that gets transformed to an array using: var result
I have an attendance table that displays how I want it to display but
I have a enrollment form where users have to input there address. I am
I already have a C# windows service that we use internally to monitor a
This question will undoubtedly be difficult to answer and ask in a way that
I've been working on the Student enrollment example/tutorial for ATK and am stuck on
suppose there is a college database name | state | enrollment ============================= Stanford |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.