Help Writing SQL Query to extract information from table

  • Hello Community,

    I'm pretty new to this forum and SQL query.
    Can some please take a look at the attached table and help me write a SQL query that will 

    a.      Group by 'FK_DATE' column and order.
    b.      For each value of FK_DATE, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    I hope this makes sense to you guys.
    Please let me know if you need further information to help me resolve this

    Regards

    Carlton

  • carlton 84646 - Thursday, December 13, 2018 6:58 AM

    Hello Community,

    I'm pretty new to this forum and SQL query.
    Can some please take a look at the attached table and help me write a SQL query that will 

    a.      Group by 'FK_DATE' column and order.
    b.      For each value of FK_DATE, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    I hope this makes sense to you guys.
    Please let me know if you need further information to help me resolve this

    Regards

    Carlton

    You'll learn a lot more by doing your own homework.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Hi SSC Guru,

    I appreciate your comments.
    Does that mean that my question is too vague to be answered? Or just too simple for anyone to bother?
    Regards

  • carlton 84646 - Thursday, December 13, 2018 6:58 AM

    Hello Community,

    I'm pretty new to this forum and SQL query.
    Can some please take a look at the attached table and help me write a SQL query that will 

    a.      Group by 'FK_DATE' column and order.
    b.      For each value of FK_DATE, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    I hope this makes sense to you guys.
    Please let me know if you need further information to help me resolve this

    Regards

    Carlton

    What happened when you tried it? Where are you stuck? We're not here to do your homework for you. You have to do that. We'll help you if you're stuck, but if you don't at least make an effort, it's very likely you won't get a response.

  • Hello Carlton,
    Please post your sample data in the form of create table and inserts scripts, what you've tried, any error messages and desired result with the sample data you provide(that may be a screenshot or picture). I won't open an excel attachment from an untrusted source and expect those looking for help to set up the sample data.
    Thanks

  • Hi SSCrazy Eights,

    Thanks for reaching out - I've had very negative feedback from other people that I've reached out to help me. 

    I have attached a screenshot of the sample table/data.

    So far, the script I have tried is:

    SELECT
    TRX_FACTS.FK_DATE
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.FK_DATE

    I don't know why to go from here. 
    Just so know you the logic was given to me to convert into a SQL query, so let me know if you need more information to write the SQL code and I will take it back to requester.

    Really appreciate it.

    Cheers

  • Hi SSCrazy Eights,

    Scratch the previous image, the table / sample data looks like the following:

  • Hi all,
    So based on my new table, see screenshot, the script I have started with is as follows:

    So the new logic will look like the following:

    a.       Group by Start_Date' column and order.
    b.      For each value of Start_Date, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    SELECT
    TRX_FACTS.Start_Date
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.Start_Date

  • carlton 84646 - Friday, December 14, 2018 6:09 AM

    Hi all,
    So based on my new table, see screenshot, the script I have started with is as follows:

    So the new logic will look like the following:

    a.       Group by Start_Date' column and order.
    b.      For each value of Start_Date, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    SELECT
    TRX_FACTS.Start_Date
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.Start_Date

    I have now tried the following:
    SELECT
    TRX_FACTS.Date_Range_ID
    ,TRX_FACTS.Start_Date
    ,TRX_FACTS.End_Date
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.Start_Date

    As you can see, I'm trying to help myself. If someone from this forum could lend a hand that would be great.

    Thanks

  • carlton 84646 - Friday, December 14, 2018 7:46 AM

    carlton 84646 - Friday, December 14, 2018 6:09 AM

    Hi all,
    So based on my new table, see screenshot, the script I have started with is as follows:

    So the new logic will look like the following:

    a.       Group by Start_Date' column and order.
    b.      For each value of Start_Date, lookup on a static table identify the Date_Range_ID
    c.      Append the records for that date to a <Date_Range_ID> file.

    SELECT
    TRX_FACTS.Start_Date
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.Start_Date

    I have now tried the following:
    SELECT
    TRX_FACTS.Date_Range_ID
    ,TRX_FACTS.Start_Date
    ,TRX_FACTS.End_Date
    FROM dbo.TRX_FACTS
    ORDER BY TRX_FACTS.Start_Date

    As you can see, I'm trying to help myself. If someone from this forum could lend a hand that would be great.

    Thanks

    SELECT
    TRX_FACTS.Date_Range_ID
    ,TRX_FACTS.Start_Date
    ,TRX_FACTS.End_Date
    FROM dbo.TRX_FACTS
    GROUP BY TRX_FACTS.Start_Date
    ORDER BY TRX_FACTS.Start_Date

Viewing 10 posts - 1 through 9 (of 9 total)

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