Query Assistance Needed Please

rhaas128

Board Regular
Joined
Jul 5, 2013
Messages
84
I have a current access query that pulls all tickets that selected users closed on a specific day from a sql database. Instead of pulling ALL tickets for the selected users, I would like to pull a random number of 5 tickets for each user. So that is what my query should do but I am not familiar with how to do this.. Below is my current query. Any and all help is appreciated!

Code:
SELECT DISTINCT dbo_Users.LastName AS [Analyst], dbo_Transactions.System, dbo_Transactions.OrderNbr, dbo_Project.ProjectNbr
 FROM (dbo_Project RIGHT JOIN (dbo_Users RIGHT JOIN (dbo_UserInfo INNER JOIN ((dbo_Transactions INNER JOIN dbo_TransComments ON dbo_Transactions.TransNbr = dbo_TransComments.TransNbr) INNER JOIN dbo_WorkOrder ON dbo_Transactions.OrderNbr = dbo_WorkOrder.OrderNbr) ON dbo_UserInfo.UserNbr = dbo_WorkOrder.UserNbr) ON dbo_Users.SSN = dbo_Transactions.SecID) ON dbo_Project.OrderNbr = dbo_Transactions.OrderNbr) INNER JOIN ((((((((IDs LEFT JOIN ((((tbl_PersonnelAct LEFT JOIN tbl_PersonnelActive AS tbl_PersonnelAct_1 ON tbl_PersonnelAct.Supervisornumber = tbl_PersonnelActive_1.AIN) LEFT JOIN tbl_PersonnelActive AS tbl_PersonnelAct_2 ON tbl_PersonnelAct_1.Supervisor = tbl_PersonnelAct_2.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_3 ON tbl_PersonnelAct_2.Supervisor = tbl_PersonnelAct_3.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_4 ON tbl_PersonnelAct_3.Supervisor = tbl_PersonnelAct_4.AIN) ON IDs.TSOID = tbl_PersonnelAct.TSOID) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_5 ON tbl_PersonnelActive_4.Supervisor = tbl_PersonnelActive_5.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_6 ON tbl_PersonnelAct_5.Supervisor = tbl_PersonnelAct_6.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_7 ON tbl_PersonnelAct_6.Supervisor = tbl_PersonnelAct_7.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_8 ON tbl_PersonnelAct_7.Supervisor = tbl_PersonnelAct_8.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_9 ON tbl_PersonnelAct_8.Supervisor = tbl_PersonnelAct_9.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_10 ON tbl_PersonnelAct_9.Supervisor = tbl_PersonnelAct_10.AIN) LEFT JOIN tbl_PersonnelAct AS tbl_PersonnelAct_11 ON tbl_PersonnelAct_10.Supervisor = tbl_PersonnelAct_11.AIN) ON dbo_UserInfo.UserID = IDs.TSOID
 WHERE (((dbo_Users.FirstName) Not Like "fn1") AND ((tbl_PersonnelAct.AIN) Is Not Null) AND ((dbo_Transactions.System) Not Like "CICS/DDE" And (dbo_Transactions.System) Not Like "TSO" And (dbo_Transactions.System) Not Like "CAS" And (dbo_Transactions.System) Not Like "DB2" And (dbo_Transactions.System) Not Like "GB Mainframe" And (dbo_Transactions.System) Not Like "Data Share") AND ((dbo_Users.LastName) Like "ln1" Or (dbo_Users.LastName)="ln2" Or (dbo_Users.LastName)="ln3") AND ((Month([secclose]))=11) AND ((Year([secclose]))=2014) AND ((Day([secclose]))=26))
 GROUP BY dbo_Users.LastName, dbo_Transactions.System, dbo_Transactions.OrderNbr, dbo_Project.ProjectNbr, dbo_Users.LastName
 ORDER BY dbo_Users.LastName;
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top