Two or more productid will be accquired by same customerid, by same shipvia, on the same day of the week of shipped date. i want the simple query for this.

consider this situation,
 Two or more productid will be accquired by same customerid, by same shipvia, on the same  day of the week of shipped date. i want the simple query for this.
my tables are  from northwind:
[orders] = OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry.
[orders details] = OrderID, ProductID, UnitPrice, Quantity, Discount.
i tried some but it is not exact, it gives wrong result.
select pd.CustomerID,pd.ProductID, pd.no_of_time_purchased, sd.ShipVia, sd.same_ship_count, shipped_day from
select ProductID,o.CustomerID,COUNT(productid) as no_of_time_purchased
from orders o join [Order Details] od on o.OrderID=od.OrderID group by ProductID,o.CustomerID
having count(od.ProductID) >1) pd
join
(select OrderID,customerid, shipvia, count(shipvia)as same_ship_count, DATENAME(DW,ShippedDate)as shipped_day from orders
group by customerid, ShipVia, ShippedDate having COUNT(ShipVia) > 1 ) sd
on sd.CustomerID=pd.CustomerID

Hi,
I think I have a solution that will at least give you a clue how to go about it. I have simplified the tables you mentioned and created them as temporary tables on my side, with some fake data to test with. I have incldued the generation of these temporary
tables for your review.
In my example I have included:
1. A customer which has purchased the same product on the same day, using the same ship 3 times,
2. Another example the same as the first but the third purchase was on a different day
3. Another example the same as the first but the third purchase was a different product
4. Another example the same as the first but the third purchase was using a different "ShipVia".
You should be able to see that by grouping on all of the columns that you wich to return, you should not need to perform any subselects.
Please let me know if I have missed any requirements.
Hope this helps:
CREATE TABLE #ORDERS
 OrderID INT,
 CustomerID INT,
 OrderDate DATETIME,
 ShipVia VARCHAR(5)
CREATE TABLE #ORDERS_DETAILS
 OrderID INT,
 ProductID INT,
INSERT INTO #ORDERS
VALUES
(1, 1, GETDATE(), 'ABC'),
(2, 1, GETDATE(), 'ABC'),
(3, 1, GETDATE(), 'ABC'),
(4, 2, GETDATE() - 4, 'DEF'),
(5, 2, GETDATE() - 4, 'DEF'),
(6, 2, GETDATE() - 5, 'DEF'),
(7, 3, GETDATE() - 10, 'GHI'),
(8, 3, GETDATE() - 10, 'GHI'),
(9, 3, GETDATE() - 10, 'GHI'),
(10, 4, GETDATE() - 10, 'JKL'),
(11, 4, GETDATE() - 10, 'JKL'),
(12, 4, GETDATE() - 10, 'MNO')
INSERT INTO #ORDERS_DETAILS
VALUES
(1, 1),
(2, 1),
(3, 1),
(4, 2),
(5, 2),
(6, 2),
(7, 3),
(8, 3),
(9, 4),
(10, 5),
(11, 5),
(12, 5)
SELECT * FROM #ORDERS
SELECT * FROM #ORDERS_DETAILS
SELECT
 O.CustomerID,
 OD.ProductID,
 O.ShipVia,
 COUNT(O.ShipVia),
 DATENAME(DW, O.OrderDate) AS [Shipped Day]
FROM #ORDERS O
JOIN #ORDERS_DETAILS OD ON O.orderID = OD.OrderID
GROUP BY OD.ProductID, O.CustomerID, O.ShipVia, DATENAME(DW, O.OrderDate) HAVING COUNT(OD.ProductID) > 1
DROP TABLE #ORDERS
DROP TABLE #ORDERS_DETAILS

Similar Messages

  • Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at http:// (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Is this a webpage that contains a link to a flv file? Please post a link to the page and tell us which link(s) are the problem flv files or else post a link to the .flv file itself.
    Alternately, click on one of the sample FLV File links on this page and tell us exactly what happens:
    http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html
    It might also help if you post the exact error message, including the path to the flv file.
    '''Note:'''
    Depending on how you have Firefox set up, clicking on a FLV File link will either save the FLV file to your computer or Firefox may open it automatically in an external application right after downloading (Firefox may ask you first). Firefox itself can't play FLV files so you need a "helper" application (or a plugin for flv files, if ther is one. You can see if Firefox is already set up to download or open FLV files by going to Firefox Preferences and looking in the Applications list. Find the FLV file type in the list and, if the action is "Open with", it should show the application that can play FLV files (e.g., VLC Media Player or Perian). See [[Managing filetypes]] for more information.

  • TS1717 iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder."  How can I fixt this?

    iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder".  How can I fix this?

    Hi pgarard1,
    If you are having issues with launching iTunes after an update, you may want to take a look at the troubleshooting in the following article:
    iTunes for Windows: Doesn't open after upgrading in Windows Vista or Windows 7
    http://support.apple.com/kb/TS2363
    Regards,
    - Brenden

  • The bookmarks toolbar is there but has no item buttons on it. How do I get the items back for this toolbar? Also would like to know if the toolbars can be put on the same line to make more room on the page (drag & drop) ??

    The bookmarks toolbar is there but has no item buttons on it. How do I get the items back for this toolbar?
    Also would like to know if the toolbar can be put on the same line to make more room on the page (drag & drop) ?? Like the menu & bookmarks toolbar could/should fit on same line. This would add more page view...
    Floyd Perry
    Thanks

    Check that you still have the "Bookmarks Toolbar items" placed on the Bookmarks Toolbar
    * Make sure that you have the "Bookmarks Toolbar" visible: "View > Toolbars"
    * Check in "View > Toolbars > Customize" that the "Bookmarks Toolbar items" is on the Bookmarks Toolbar
    * If the "Bookmarks Toolbar items" is not on the Bookmarks Toolbar then drag it back from the Customize window onto the Bookmarks Toolbar
    * If you do not see the "Bookmarks Toolbar items" then click the "Restore Default Set" button
    You can only move the content from a toolbar onto other toolbars if all toolbars support that feature. You need to check that in the options of each toolbar.

  • In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String

    In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .

    Hi Srinath,
    The below blog might be useful
    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
    PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
    regards,
    Harish

  • When install iTunes 11.1.4   It says Apple Mobile Device Service service will not start.  It was started when I began the installation.  Is this an Apple software bug?

    When install iTunes 11.1.4   It says Apple Mobile Device Service service will not start.  It was started when I began the installation.  Is this an Apple software bug?

    I have this issue. It isn't the MSVCR80 issue. No matter what I do nothing will let me even INSTALL Apple Moblie Device. Further details are in my thread:
    https://discussions.apple.com/thread/5831093

  • Hi, I just updated my mac from version10.6 to 10.9.3 os mavericks. i went to open iPhoto and it says "Your photo library will not be readable by previous versions of iPhoto after the upgrade." does this mean I have lost all photos i had in there?

    Hi, I just updated my mac from version10.6 to 10.9.3 os mavericks. i went to open iPhoto and it says "Your photo library will not be readable by previous versions of iPhoto after the upgrade." does this mean I have lost all photos i had in there? It does not give me a choice, it just says quit or upgrade? p.s. i didn't realise ther was  a way to back up my computer beforehand, which i am guessing this is time machine?

    1. No, you haven't.
    2. Back up the iPhoto library(this can be done through Time Machine or by dragging it to a drive, partition, or disk image formatted as Mac OS Extended) and then click Upgrade.
    3. Aside from Time Machine and drag-copying items from your home folder, programs such as the Disk Utility, Carbon Copy Cloner, and SuperDuper can make backups.
    (108026)

  • Hello , Recently my company purchased a Fujifilm X30 . We were surprised that Adobe has not updated the plug in for this camera. Since we are your customers, we would like to know, when they will perform this update ? For us it is very important to work w

    Hello , Recently my company purchased a Fujifilm X30 . We were surprised that Adobe has not updated the plug in for this camera. Since we are your customers, we would like to know, when they will perform this update ? For us it is very important to work with all our tools work quickly and efficiently, I guess I understand.
    We await your response .
    Thank you very much .

    This is a user to user forum with "some" Adobe staff participation, make requests at this link
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Just bought a 3TB Time Capsule for a small office. Will have 4 users with MacBooks. What would ne the best setup for time machine individual backups and internet sharing in a secure way?

    Just bought a 3TB Time Capsule for a small office. Will have 4 users with MacBooks. What would ne the best setup for time machine individual backups and internet sharing in a secure way?

    Set up each Mac for Time Machine backups in the normal way.  Time Machine will keep each backup separate on the Time Capsule, so users will only be able to see the backups of their own Mac.
    Yes....there are convoluted workarounds that might allow one user to see the backups of another.....IF...they know the administrator password of the "other" Mac.
    As far as Internet sharing, all users will have access to the Internet if they have a wired or wireless connection. If a Mac connects using wireless, it is possible to limit the time that they are allowed to connect to the network.
    For example, you might limit the ability to connect to the wireless from say each Weekday from 8 AM to 6 PM.
    With a wired Ethernet connection, you cannot limit access times to the Internet.

  • Will be International for 5 months and want to remove plan for this time

    I will be studying in Austria for an extended period of time and would like to bring my iphone5, but not use any sort of plan with it (I'll just use wifi and as a camera). Right now I have a contract for several years (unlimited talk, text, and 2GB data) and pay $60 a month for it. There are two other phones on my account. I was wondering if I could just remove my phone for these months (and not pay for a service I wouldn't even be using) and then resume my plan when I return in July.

    You can't "remove" your phone for this time without paying the ETF since you are under contract.
    Verizon allows you to "suspend" service without billing for 90 days at a time. Once the 90 days is up, your service will automatically restart. Once it restarts, you can go back in and suspend it again. Verizon allows you to do this twice in a year for a total of up to 180 days in a year. Unfortunately, with the service automatically restarting again after 90 days, you will most likely have 1 month of service for which to pay.
    While in Austria, you should be able to simply remove your Verizon SIM card and insert a SIM card from a local provider to get service thru them.

  • The quicklink row on the overall window for this version of firefox continually skips two icons/links, why?

    I didn't have this issue on any previous version of my favorite browser, but now when I remove the 'Name' that would show up next to the icon, to only show the logo of my bookmarks, two icons that are adjacent to each other do not allow me to select it. However I try to arrange them, or even duplicate the link on that row of icons some other two adjacent links will repeat the issue I'm writing about here.
    Thank you in advance for your help with this.
    Long live Mozilla Firefox.

    Thanks but you're only telling me stuff I already know, that dosen't explain how I get the new version of Firefox to look neat and tidy like it always used to. I can no longer have all my icons that I use, I can no longer access things as easily as I could and the whole thing looks very bare and basic now! A bigger mess than even Google Chrome.
    I've spent most of this evening trying to get stuff back that is now lost because of this 'upgrade' and I'm now giving up with it. Well done! You've totally ruined what was the best browser for years.

  • Re: More than one planned order on same day

    Dear All,
    I am getting more than one planned order for the same day in MD04 after I run MRP run. My requirement is that the planned order should get clubbed.
    My lot size is WB & 2: collective requirement setting.
    Please advice.
    Regards,
    Vivek Sharma

    Karthick,
    I am getting more than one planned order on same date.If I check any of the planned order for pegging requirements I find that the planned order has been created after clubbing all the requirements( the Raw material is being used in morethan one FG )
    Now the issue Is :
    09.06.2010     PldOrd     0019211763/STPO     13.02.2010     30     159.500
    09.06.2010     PldOrd     0019211764/STPO     18.02.2010     30     1,536
    09.06.2010     PldOrd     0019211765/STPO     25.02.2010     30     787.500
    09.06.2010     PldOrd     0019211766/STPO     11.03.2010     30     2,536.755
    09.06.2010     PldOrd     0019211767/STPO     29.03.2010     30     862.500
    09.06.2010     PldOrd     0019211768/STPO     13.04.2010     30     108.750
    09.06.2010     PldOrd     0019211769/STPO     27.04.2010     30     1,678.500
    09.06.2010     PldOrd     0019211770/STPO     30.05.2010     30     980.745
    So I dont understand how is this happening.
    Regards

  • Will there be a RAW plugin for Elements 12 supporting the Canon EOS 7D MkII - or when will the DNG converter for this be available?

    I've just bought a Canon EOS 7D MkII but cannot open the RAW files in Elements 12. I also can't use the latest DNG Converter to convert them - will either option become available and if yes how long is it likely to take please?
    Thanks, Sarah

    Hi,
    The Canon 7D Mk II is currently not supported by any version of camera raw.
    It is expected that Camera raw 8.7 will include support and we are hoping that it will be released soon.
    PSE 12 has ceased to be updated - you will either need to update to PSE 13 or use the DNG 8.7 converter (when it becomes available) to convert the CR2 files to DNG files - PSE 12 will then beable to use the DNG files.
    Brian

  • Trying to send a meeting request in Outlook 2010. Error: "the meeting is not in the calendar folder for this account. responses to this meeting will not be tallied

    Trying to send a meeting request in Outlook 2013 Error: "The meeting is not int he calender folder for this account. responses to this meeting will not be Tallied.
    Please let me know what should I do?
    I have set the account as default what should be my next step?

    Hi,
    Please try the following points to narrow down the issue:
    1. Please check whether the default Calendar folder is checked when you created the meeting request and sent it out.
    2. Please check whether there is any shared calendar opened in your Outlook and the meeting request is created on behalf of the shared calendar instead of your own calendar.
    3. Create a new Outlook profile and create a test meeting request to have a try.
    Additionally, here is a similar thread for your reference:
    https://social.technet.microsoft.com/Forums/en-US/b9e9e47c-13f2-4522-a0c4-14a4371e740c/trying-to-send-a-meeting-request-in-outlook-2010-error-the-meeting-is-not-in-the-calendar-folder?forum=exchangesvrclientslegacy
    Regards,
    Winnie Liang
    TechNet Community Support

  • Why can't I have the Samsung Haven replaced without paying for a new phone since the battery needed for this model will not hold a charge more then 24 hrs?

    The Haven is my husbands phone and he calls me from work every night and we talk about 15 minutes.  He calls my verizon phone so there is no charge but the problem we have is the phone will not stay charged.  We took it in and had it tested along with the house charge and the car charge.   All three device are fine so they ordered us a new battey.  We put that in and the same thing happens.  We don't text, receive text, take or send pictures.    We have texting blocked so nothing can use up his battery and yet it still dies.  Can you please tell me how we can get this phone replaced without buying a new one.  The contract isn't up for renewal until Oct. 2013.  We have been long time customers of verizon and I feel we should be able to get a product replaced if it is a defective product the company is selling.  It seems Verizon knows there is a problem since there have been so many complaint filed in the last 9 months.  If we buy something from Home Depot or Lowes and that product is not working right, they replace it and they go back to the companies that supply it.  I am willing to bet Samsung would take Verizon,s complaint more seriously then they would an average consummer.  Please tell me Verizon is finally listening to their customers.

        Hi THerman!
    We definitely don't want you having a phone described as a lemon so let's work on getting everything back up to a peachy status. What you've indicated is certainly an issue. So, let's fix this.
    First, when it comes to your calls not ringing or registering in your log, my recommendation is to update your phone. To do this, simply dial *228, choose option 2, wait for completion and for your phone to restart itself. This will have it resync with our network for optimal usage. Regarding the battery, personally I like to pull my battery every now and again for up to 60 seconds before reinserting (all while the phone is powered off). If you don't notice improvement, we may need to look into a replacement if life is shortlived below what was described prior.
    EvanO_VZW
    VZW Support
    Follow Us On Twitter @VZWSupport

Maybe you are looking for

  • How to use Excel file in BDC

    how to transfer data from an execel file to an internal file for a BDC program?

  • Hardware Color Cursor Problem in Windows 8.1

    I have 2 issues related to the cursor on Win8.1 with 2 display adapters.  It seems Windows 8.x problem. Issue #1, Primary display adapter is using hardware color cursor and secondary adapter is software cursor. It will have cursor left over on the se

  • Company code in deferred Transfer Tax

    Dear sir, When select multi company code in selection screen of Deferred transfer tax , the system will show the selected Company (to) to any document no. which is selected to transfer instead of the real company code of document. ASAP with thanks, k

  • How do I stop my iPhone 4 from duplicating recurring events?

    Recently, my iPhone 4 started duplicating all my recurring calendar events (though they only show up in my Outlook as a single event on a particular day, they show up twice on a particular day on my iPhone calendar . . . one has a purple dot next to

  • 4620 printer

    when i put the cartrige in that came the printer, the error is use setup cartridge that came with your printer.and nothing come up but that error.