sql - Join a single row in one table to n random rows in another -


Is it possible to join SQL Server, which can be included in table Random Random Rows from each row? For example, I have a customer table, a product table and an order table. I want to include each customer in 5 random products and put these lines in the order table. (And each client should be included in their own 5 random rows, I do not want all customers to be included in the same 5 rows)

Is this possible? I am using SQL Server 2005 and it is fine if the solution is specific to that.

This is a strange requirement, but I'm basically creating a small data generator to generate some random data.

See something like this

  DECLARE @Products table (id Int, Prod VARCHAR (10)) Include the Custom Tab (ID INT) @ product selection in 1, select 'A' Select the product 2, select the products in 'B' 3, 'C' Select INSERT @ products, include the customer's choice in 'D' @ Customer Selection 2 - Select a cross product, but apply a random serial number per customer - and only the 'top' n items Has that you need. ; As with Vals (SELECT c.id Customer ID, Paid Product ID, P. Promotion, ROW_NUMBER () (News by CID Order New) Roline Number @ Customer C, @ Products p) SELECT * FROM Vals Where line number & lt; = 2  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -