Row Counts Based on Distinct Values from Multiple Tables

  • Hello Everyone,

    I am trying to create a query that outputs the following data from multiple tables.

    Here is an example of the raw data right now

    Date | MachineNumber | TestName

    ---------------------------------------

    1/1/2015 | 500 | Something

    1/1/2015 | 500 | Something

    1/1/2015 | 500 | Something

    1/1/2015 | 500 | Something

    1/1/2015 | 510 | NewTest

    1/1/2015 | 510 | NewTest

    1/1/2015 | 510 | NewTest

    1/1/2015 | 620 | Test#1

    Here is the desired counted output, I would like to pull distinct Date, MachineNumber, TestName and then count how many times they occur in the raw data form

    Note: I do need to perform a case on the date because right now its in a datetime format and I only need the date.

    Date | MachineNumber | TestName | TestOccuranceCount

    -----------------------------------------------------------------

    1/1/2015 | 500 | Something | 4

    1/1/2015 | 510 | NewTest | 3

    1/1/2015 | 620 | Test#555 | 1

    I am pulling three columns with the same names from 8 different tables. What I need to display the date, machine & test name and count how many times a test was run on a machine for that date. I have a feeling this can be handled by SSAS but haven't built an analysis cube yet because I am unfamiliar with how they work. I was wondering if this is possible in a simple query. I tried to set something up in a #Temp table. Problem is the query takes forever to run because I am dealing with 1.7 Million rows. Doing an insert into #temp select columnA, columnB, columnC from 8 different tables takes a bit. Any help is appreciated!

    Thanks!!

  • basically you just need to group by those fields, with a count(1).

    We can give you the code if you tell us what the multiple tables are and how they join together

    If it was one table like the sample you gave it would be:

    SELECT [Date],MachineNumber,TestName, count(1) TestOccuranceCount

    FROM #TableName

    GROUP BY [Date],MachineNumber,TestName

    You can do the same pulling the data from multiple tables. Just write the query that would pull those three fields, add the count and the group by those 3 fields.

    Note: You can't include any other fields in the select list unless they are aggregated or part of the group.

  • Thanks for the quick response, here's the kicker the only possible common denominator is the product number that is tested.

  • cstg85 (1/15/2015)


    Thanks for the quick response, here's the kicker the only possible common denominator is the product number that is tested.

    I have no idea what you mean. Maybe you could work up a sample version of your problem with DDL and sample data. Are you saying product number is the only way to join the tables? There wasn't even a product number in your sample

  • Many ways of doing this, here is one

    😎

    USE tempdb;

    GO

    SET NOCOUNT ON;

    DECLARE @SAMPLE_DATA TABLE

    (

    [Date] DATE NOT NULL

    ,MachineNumber INT NOT NULL

    ,TestName VARCHAR(25) NOT NULL

    );

    INSERT INTO @SAMPLE_DATA (Date, MachineNumber, TestName)

    VALUES

    ---------------------------------------

    ('1/1/2015',500,'Something')

    ,('1/1/2015',500,'Something')

    ,('1/1/2015',500,'Something')

    ,('1/1/2015',500,'Something')

    ,('1/1/2015',510,'NewTest')

    ,('1/1/2015',510,'NewTest')

    ,('1/1/2015',510,'NewTest')

    ,('1/1/2015',620,'Test#1')

    ;

    ;WITH BASE_DATA AS

    (

    SELECT

    SD.MachineNumber

    ,SD.TestName

    ,MIN([Date]) OVER

    (

    PARTITION BY SD.TestName

    ) AS FIRST_OCC

    ,MAX([Date]) OVER

    (

    PARTITION BY SD.TestName

    ) AS LAST_OCC

    ,COUNT(*) OVER

    (

    PARTITION BY SD.TestName

    ) AS TestOccuranceCount

    FROM @SAMPLE_DATA SD

    )

    SELECT DISTINCT

    BD.MachineNumber

    ,BD.TestName

    ,BD.FIRST_OCC

    ,BD.LAST_OCC

    ,BD.TestOccuranceCount

    FROM BASE_DATA BD;

    Results

    MachineNumber TestName FIRST_OCC LAST_OCC TestOccuranceCount

    ------------- ------------------------- ---------- ---------- ------------------

    500 Something 2015-01-01 2015-01-01 4

    510 NewTest 2015-01-01 2015-01-01 3

    620 Test#1 2015-01-01 2015-01-01 1

  • Sorry about that.

    So each table is a type of test, (as you can see from my sloppy code below.) In those tables we store the date/time, serial number, test type (Test name) and specific data for each test. The only common column between all tables is one I didn't mention which is the product number. (my apologies).

    create table #Temp

    ( [Date] date

    , [SerialNumber] int

    , [TestType] varchar(20))

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Attn];

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Cutoff];

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Banndwidth]

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [NA]

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [MFD]

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Geo]

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Oct]

    insert into #Temp

    select cast([TestDateTime] as [date] ), SerialNumber, TestType from [Coat]

    select count(TestType)

    from #Temp

    drop table #Temp

    Please let me know if this helps at all.

  • The optimal thing we would need would be create table definitions for samples of the 8 tables,

    insert commands to insert test data into them, and then a view of what the query output should be.

    When you say product number is the only data in common, does that mean each test has its own serial number?

    Do you need data for one product number, or grouped for each product number, or grouped across product numbers?

    I suspect based on what you tried with a temp table what you need is a union all between each table query in a cte, and then a query that groups all the data. But its hard to tell for sure without a concrete example

  • Nevyn,

    To answer your questions

    1) Each product number can be tested by each one of the tests.

    2) I need the data sorted by date, then grouped by serial number and test type (see below)

    - The "serial number" belongs to each piece of test equipment, so lets call it Equipment number just for clarity

    3) I do not need it grouped by product number.

    The end goal is to see the total number of tests for that day on that piece of equipment (serial number) by the test type. So if on 10-07 I run 3 test types I want to see how many times each test was run on that machine.

    I have uploaded an attachment including the DDL & DML.

    Thank you,

    cstg85

  • There seem to be some problems with the test data. Different number of columns and missing quotes on the insert from attn to start

  • Here is what I used as testing tables and the query:

    Testing Data

    -- attn table

    CREATE TABLE [dbo].[Attn](

    [AttnID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [ProductNumber] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    [Length] [decimal](18, 3) NULL,

    CONSTRAINT [PK_Attn] PRIMARY KEY CLUSTERED

    (

    [AttnID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- bandwidth table

    CREATE TABLE [dbo].[Bandwidth](

    [BandwidthID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [ProductNumber] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](20) NULL,

    [Length] [decimal](6, 3) NULL,

    CONSTRAINT [PK_Bandwidth] PRIMARY KEY CLUSTERED

    (

    [BandwidthID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- coat table

    CREATE TABLE [dbo].[Coat](

    [CoatID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [ProductNumber] [varchar](30) NULL,

    [TestType] [varchar](30) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [CABID] [varchar](30) NULL,

    [Length] [decimal](6, 3) NULL,

    CONSTRAINT [PK_Coat] PRIMARY KEY CLUSTERED

    (

    [CoatID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- cutoff table

    CREATE TABLE [dbo].[Cutoff](

    [CutoffID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [ProductNumber] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    [Length] [decimal](18, 3) NULL,

    CONSTRAINT [PK_Cutoff] PRIMARY KEY CLUSTERED

    (

    [CutoffID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- geo table

    CREATE TABLE [dbo].[Geo](

    [GeoID] [int] NOT NULL,

    [MacroID] [int] NULL,

    [FiberID] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    CONSTRAINT [PK_Geo] PRIMARY KEY CLUSTERED

    (

    [GeoID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- mfd table

    CREATE TABLE [dbo].[MFD](

    [MFDID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [ProductNumber] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    [Length] [decimal](18, 3) NULL,

    CONSTRAINT [PK_MFDID] PRIMARY KEY CLUSTERED

    (

    [MFDID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- na table

    CREATE TABLE [dbo].[na](

    [naID] [int] NOT NULL,

    [MacroID] [int] NULL,

    [FiberID] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    CONSTRAINT [PK_na] PRIMARY KEY CLUSTERED

    (

    [naID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- oct table

    CREATE TABLE [dbo].[oct](

    [octID] [int] NOT NULL,

    [MacroID] [int] NOT NULL,

    [FiberID] [varchar](30) NULL,

    [TestType] [varchar](20) NULL,

    [SerialNumber] [int] NULL,

    [TestDateTime] [datetime] NULL,

    [Operator] [varchar](30) NULL,

    CONSTRAINT [PK_oct] PRIMARY KEY CLUSTERED

    (

    [octID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    -- insert statements

    -- attn

    insert into attn

    values (1, 1, 'fibid1', 'Atten-PK2500', 55242248, '2014-10-07 14:45:44.000', 'p1','0.100')

    insert into attn

    values(2, 1, 'fibid1', 'Atten-PK2500', 55242248, '2014-10-07 14:45:44.000', 'op1', '0.100')

    insert into attn

    values(3, 1, '14-D05', 'Atten-PK2500', 55242248, '2014-10-08 15:11:17.000', 'smr-clad', '0.520')

    insert into attn

    values(4, 1, '14-D05', 'Atten-PK2500', 55242248, '2014-10-08 15:11:17.000', 'smr-clad', '0.520')

    -- bandwidth

    -- no rows inserted yet, can be ignored.

    -- coat

    insert into coat

    values (4,8, 'fib1', 'COAT', 53172395, '2014-10-07 10:35:10.000','op1',NULL)

    insert into coat

    values (5,8, '14-013', 'COAT', 53172395,'2014-10-08 08:32:48.000','jpa-Bottom',NULL)

    insert into coat

    values (6,8, '14-013', 'COAT', 53172395,'2014-10-08 08:46:02.000','jpa-BottomRetest',NULL)

    -- cutoff

    insert into Cutoff

    values(1,2,'14-C109','Cutoff',55242278,'2014-10-24 21:43:42.000','dmk-top','0.002')

    insert into Cutoff

    values(2,2,'14-C109','Cutoff',55242278,'2014-10-24 21:43:42.000','dmk-top','0.002')

    insert into Cutoff

    values(3,2,'14-C1091','Cutoff',55242278,'2014-10-08 21:43:42.000','dmk-top','0.002')

    insert into Cutoff

    values(4,2,'14-C109','Cutoff',55242278,'2014-10-08 21:43:42.000','dmk-top','0.002')

    --geo

    insert into geo

    values(1,6,'13-B145top', 'GEO', 53172395, '2014-10-07 07:53:47.000', 'db')

    insert into geo

    values(2,6,'14-0138_loose', 'GEO', 53172395, '2014-10-07 11:37:51.000', 'smr')

    insert into geo

    values(3,6,'11-C024', 'GEO', 53172395, '2014-10-08 08:45:09.000', 'jpa-Bottom')

    insert into geo

    values(4,6,'11-C024', 'GEO', 53172395, '2014-10-08 09:13:47.000', 'jpa-Bottom')

    -- mfd

    insert into mfd

    values(1, 5, 'fibid1', 'MFD', 55242278, '2014-10-07 12:45:33.000', 'op1', '0.100')

    insert into mfd

    values(2, 5, '14-C1091', 'MFD',55242278, '2014-10-07 21:54:37.000', 'dmk-bottom', '0.002')

    insert into mfd

    values(3, 5, '14-C1091', 'MFD',55242278, '2014-10-08 21:54:37.000', 'dmk-bottom', '0.002')

    insert into mfd

    values(4, 5, '14-C1091', 'MFD',55242278, '2014-10-08 15:00:08.000', 'dmk', '0.002')

    -- na

    insert into na

    values(1, 4, 'fib1', 'NA', 55242278, '2014-10-07 14:49:13.000', 'op1')

    insert into na

    values(2, 4, 'fib1', 'NA', 55242278, '2014-10-07 14:49:13.000', 'op1')

    insert into na

    values(3, 4, '14-B1563', 'NA', NULL, '2014-10-08 11:03:53.000', 'db')

    insert into na

    values(4, 4, '14-B1563', 'NA', NULL, '2014-10-08 11:03:53.000', 'db')

    -- oct

    insert into oct

    values(1, 7, 'fib1', 'OCT', 53172395, '2014-10-07 11:38:22.000', 'op1')

    insert into oct

    values(2, 7, 'fib1', 'OCT', 53172395, '2014-10-07 11:38:22.000', 'op1')

    insert into oct

    values(3, 7, '14-B1558', 'OCT', 53172395, '2014-10-08 11:57:56.000', 'db')

    insert into oct

    values(4, 7, '14-B1558', 'OCT', 53172395, '2014-10-08 11:57:56.000', 'db')

    Query

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Coat

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Cutoff

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Geo

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM na

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM oct

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Attn

    )

    SELECT TestDate,SerialNumber,TestType,count(1) NumberOfTests

    FROM UnionTables

    GROUP BY TestDate,SerialNumber,TestType

    Query output

    TestDateSerialNumberTestTypeNumberOfTests

    2014-10-0753172395COAT1

    2014-10-0753172395GEO2

    2014-10-0753172395OCT2

    2014-10-0755242248Atten-PK25004

    2014-10-0755242278NA2

    2014-10-08NULLNA2

    2014-10-0853172395COAT2

    2014-10-0853172395GEO2

    2014-10-0853172395OCT2

    2014-10-0855242248Atten-PK25004

    2014-10-0855242278Cutoff2

    2014-10-2455242278Cutoff2

  • I may be missing something but when I run the query it doesn't display the number of tests. What am I doing wrong?

  • Edit: its my fault, copy and paste on my query cut off the top of it. Also think I was missing one table and duplicating one as I did it in a hurry.

    Try this.

    ;

    WITH UnionTables AS(

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Attn

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Bandwidth

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Coat

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Cutoff

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Geo

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM MFD

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM na

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM oct

    )

    SELECT TestDate,SerialNumber,TestType,count(1) NumberOfTests

    FROM UnionTables

    GROUP BY TestDate,SerialNumber,TestType

    If you need an explanation for the WITH or UNION ALL syntax, let me know

  • Wow, what a query! I have a question about the Number of Tests count. It appears that it does a count and as long as the serial number and test type match. Is it possible to get it to count just the rows for that day? The results I receive show the same count number for dates that have matching serial number and test type.

    Okay, I have to ask how that WITH statement works, this is a concept that is completely new to me! I will do a little research on the UNION ALL statements. I have learned so much, thank you.

  • It appears that it does a count and as long as the serial number and test type match. Is it possible to get it to count just the rows for that day? The results I receive show the same count number for dates that have matching serial number and test type.

    I'm not 100% what you mean by this. Could you show me an example with sample data of what this query is returning and what you would like it to return?

    The query right now should be looking at each day, and giving a count of each test/serial number combination for that day. For example, COAT had one record for the 7th, and 2 for the 8th, all with the same type and serial. When I run the query, I get two rows, one for the 7th showing a count of 1, and one for the 8th showing a count of 2. Is that not right?

    Okay, I have to ask how that WITH statement works, this is a concept that is completely new to me! I will do a little research on the UNION ALL statements. I have learned so much, thank you.

    The WITH syntax is known as a COMMON TABLE EXPRESSION (or CTE for short). Everything within the brackets is essentially one query, and the WITH statement allows you to logically treat what would result from that query as if it were a table.

    It is important to recognize that this is just a way of presenting and formatting the LOGIC you want to achieve to SQL server. It does NOT mean that it pre-processes this query (like a temp table).

    Using this is similar to using a derived table if you've seen those before. The handy thing with a CTE, though, is that you can reference it more than once in the query that follows. CTE's can even be used recursively, although there are performance risks in doing so.

    For your particular problem, the CTE was not strictly necessary as each test had its own table. You could achieve the same by grouping and counting in each table query and then using UNION ALL to append them together.

  • For fun, few different counts/metrics

    😎

    USE tempdb;

    GO

    SET NOCOUNT ON;

    ;with UnionTables as

    (

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Coat

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Cutoff

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Geo

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM na

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM oct

    UNION ALL

    SELECT CAST(TestDateTime AS Date) TestDate,

    SerialNumber,

    TestType

    FROM Attn

    )

    ,BASE_DATA AS

    (

    SELECT

    SD.SerialNumber

    ,SD.TestType

    ,SD.TestDate

    ,MIN(TestDate) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    ) AS FIRST_OCC

    ,MAX(TestDate) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    ) AS LAST_OCC

    ,DATEDIFF(DAY,MIN(TestDate) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    )

    ,MAX(TestDate) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    )) + 1 AS DURATION_DAY

    ,COUNT(*) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    ) AS TestOccuranceCount

    ,COUNT(*) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    ,SD.TestDate

    ) AS TestOccCountPerDay

    ,COUNT(*) OVER

    (

    PARTITION BY SD.SerialNumber

    ) AS TotalCountSerial

    ,((COUNT(*) OVER

    (

    PARTITION BY SD.SerialNumber

    ,SD.TestType

    ) + 0.0 ) / (COUNT(*) OVER

    (

    PARTITION BY SD.SerialNumber

    ) + 0.0)) * 100 AS TestPercOfTot

    FROM UnionTables SD

    )

    SELECT DISTINCT

    BD.SerialNumber

    ,BD.TestDate

    ,BD.TestType

    ,BD.FIRST_OCC

    ,BD.LAST_OCC

    ,BD.DURATION_DAY

    ,BD.TestOccuranceCount

    ,BD.TestOccCountPerDay

    ,BD.TotalCountSerial

    ,BD.TestPercOfTot

    FROM BASE_DATA BD;

    Results

    SerialNumber TestDate TestType FIRST_OCC LAST_OCC DURATION_DAY TestOccuranceCount TestOccCountPerDay TotalCountSerial TestPercOfTot

    ------------ ---------- ------------------------------ ---------- ---------- ------------ ------------------ ------------------ ---------------- ---------------------

    NULL 2014-10-08 NA 2014-10-08 2014-10-08 1 2 2 2 100.00000000000000

    53172395 2014-10-07 COAT 2014-10-07 2014-10-08 2 3 1 11 27.27272727272700

    53172395 2014-10-07 GEO 2014-10-07 2014-10-08 2 4 2 11 36.36363636363600

    53172395 2014-10-07 OCT 2014-10-07 2014-10-08 2 4 2 11 36.36363636363600

    53172395 2014-10-08 COAT 2014-10-07 2014-10-08 2 3 2 11 27.27272727272700

    53172395 2014-10-08 GEO 2014-10-07 2014-10-08 2 4 2 11 36.36363636363600

    53172395 2014-10-08 OCT 2014-10-07 2014-10-08 2 4 2 11 36.36363636363600

    55242248 2014-10-07 Atten-PK2500 2014-10-07 2014-10-08 2 4 2 4 100.00000000000000

    55242248 2014-10-08 Atten-PK2500 2014-10-07 2014-10-08 2 4 2 4 100.00000000000000

    55242278 2014-10-07 NA 2014-10-07 2014-10-07 1 2 2 6 33.33333333333300

    55242278 2014-10-08 Cutoff 2014-10-08 2014-10-24 17 4 2 6 66.66666666666600

    55242278 2014-10-24 Cutoff 2014-10-08 2014-10-24 17 4 2 6 66.66666666666600

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply