0

I have a table where is over 50 000 rows, from that table I want to select random percentages of rows.

Below are member types that are stored in one column(Member Type) and I need to select random percentage of each of the 7 member type. Also the percentages are not from the total number of rows but only random 8000 from that table.

  • Private Associate - 40% from random 8000 rows
  • Associate Member Under 35 - 21% from random 8000 rows
  • Private Full Member - 13% from random 8000 rows
  • Public Associate - 12% from random 8000 rows
  • Associate Student - 8% from random 8000 rows
  • Public Full Member - 3% from random 8000 rows
  • Full Member U35 - 1% from random 8000 rows

What would be the best solution for this?

Andrea
  • 11,801
  • 17
  • 65
  • 72
  • Rows in *what*? A spreadsheet? A database? A dataframe in R or pandas? What *language* are you using? In any event, what is the problem? 40% of 8000 is 3200 -- just randomly select 3200 rows from the Private Associate rows. Similarly for the other categories. Just how you would do that depends heavily on your answers to the above questions. – John Coleman Aug 22 '17 at 15:19
  • My apologies, in database using SQl Management Studio 2014. I have never constructed similar query, right it makes sense. I know math. In my query I am joining 7 tables. One of them is the one where Member Type is store, my question would be where in the query do I specify the number of rows for each category ? –  Aug 22 '17 at 18:17
  • LEFT JOIN vw_client_uli_member_type WITH (NOLOCK) ON cst_key=mem_cst_key this is a join for the table where I would like to select the specified number of rows. Would I specify it here? Thanks John –  Aug 22 '17 at 18:21
  • Stick an ORDER BY NEWID() on the query – Milney Aug 25 '17 at 10:24
  • See this link to randomize your data: https://stackoverflow.com/a/1209946/100283 anthem take a look at the link to top percentage: https://learn.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql – Mark Kram Aug 25 '17 at 10:25

0 Answers0