+ Reply to Thread
Results 1 to 11 of 11

Finding records with a value <0.8 of AVG in a mixed dataset

  1. #1
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Finding records with a value <0.8 of AVG in a mixed dataset

    I'm not at all confident in SQL, simple selects and inserts is about it....however, I have a requirement to do the following:

    I have a table in Access with airline tickets listed. There's a FromCity, ToCity, CurrentPrice, FlightDate and lots more irrelevant fields. What I'm trying to create is a query that will show me these 3 fields for each individual ticket that has a CurrentPrice < 0.8*AVG(CurrentPrice) for it's combination of FromCity / ToCity on each day in the entire dataset.

    I could VBA it and bring back each combination of From / To in turn and a run a query on each one.....but I'm hoping there's a way to do this in one query in SQL. Oh and results are coming into an Excel page so I'm ADOing it and running SQL on the Access table from Excel VBA rather than using an Access form.

    Even pointing me a direction to start in would be huge assistance here. My SQL is terrible.
    Last edited by BellyGas; 12-23-2021 at 10:40 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 VersionVersion 2411 Win 11
    Posts
    24,418

    Re: Help an SQL amateur please.

    Instead of trying to write SQL, why not just use the UI in the query builder? If you post some sample data in an Access DB, I may be able to help by building it in the UI and then copying the SQL statement that is generated. Do it the easy way and use the tools available rather than the hard way.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2412 (Windows 11 24H2 64-bit)
    Posts
    88,707

    Re: Help an SQL amateur please.

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  4. #4
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Help an SQL amateur please.

    Hey Ali, LTNS. Merry Christmas. Title edited. It's been so long since I've been here I'd completely forgotten about rule #1.

    Let me just cut this dataset down and I'll post it...

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    https://www.dropbox.com/s/66ji6o26t5...ets.accdb?dl=0

    The data is laid out as multiple tickets for every day of the year for multiple routes and may be being sold by one of lots of vendors at different prices. I'm trying to find any tickets that have been bargain priced compared to other tickets on the same route (there may be multiple flights on the same route) on the same day. ie, its no use comparing prices on sunday to those on monday.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 VersionVersion 2411 Win 11
    Posts
    24,418

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    I have created two queries. One to calculate what 80% of the Average ticket price for each leg and the second to compare that number with each ticket sold.

    First query:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    That first query is about as far as I got before realising that the AVG of CurrentPrice needs to be calculated for every individual route in the data and 365 times for each route (every day), not just once for the entire field or once per unique combination of to/from. Comparing ticket prices from say...a wednesday in the middle of a school term in May to a ticket price on Christmas eve when Christmas eve is a Sunday, for example, isn't useful so I have to calculate the price every day and compare each days ticket prices to the AVG for that day only.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 VersionVersion 2411 Win 11
    Posts
    24,418

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    That is more complicated than I have time to figure out. A suggestion that you may want to explore is to build your query with a parameter for the date and then try and modify the queries I provided so that it is for a specific date. With each iteration of dates, you can export your data to Excel and save it so that in the end, you will have 365 query results in an excel file that you can analyze.

  9. #9
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    I've just realised, I'm being absolutely bone-headed.

    The end result of this is a report that does not need to be updated in real time, in fact it really only needs to be run once.....which means it can take as long as it likes to run.....which means I can do this in VBA and loop through as many SQL queries as I like. Thanks for the help though! Merry Christmas.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 VersionVersion 2411 Win 11
    Posts
    24,418

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    Did a little bit of work. Here is a revamp on the first query. Cannot get second one to work yet.

    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Finding records with a value <0.8 of AVG in a mixed dataset

    Well that's 3/4 of the job done right there, thanks Alan! I think I can do the rest, just one at a time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. a greeting from VBA amateur
    By EJOYVOID in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 09-30-2021, 07:11 AM
  2. Making a chart to assess employee value (amateur)
    By alxplx in forum Excel General
    Replies: 1
    Last Post: 11-01-2020, 10:26 AM
  3. I love playing with excel, but on a purely amateur level.
    By Auld Pharrrt in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 05-23-2018, 05:02 PM
  4. Enthusiastic amateur in over his head!
    By kdisley in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-18-2013, 12:21 PM
  5. Lasik doc amateur excel user
    By visionxcl in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 08-24-2012, 02:34 PM
  6. Amateur VBA developer seeks further assistance...
    By colofnature in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2006, 10:15 PM
  7. AMATEUR REPORTERS WANTED!
    By Herb in forum Excel General
    Replies: 0
    Last Post: 08-08-2006, 10:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1