select subset of data with labels in specific column balanced in TSQL

select subset of data with labels in specific column balanced in TSQL

I have about 4M records in a table. Each record in this table is distinct. One of the columns 'labels' has two distinct values L1 and L2. I want to randomly select 100000 records such that 50% of this data has label L1 and the rest has L2.

I have about 4M records in a table. Each record in this table is distinct. One of the columns 'labels' has two distinct values L1 and L2. I want to randomly select 100000 records such that 50% of this data has label L1 and the rest has L2.

Eg : If the following table is the mastertable and has about 10 rows

s_key  C1    C2    labels
s1     0.2   0.1    L1
s2     0.3   0.3    L1
s3     0.25  0.32   L2
s4     1.4   0.5    L1
s5     2.3   9.0    L1
s6     1.2   0.8    L1
s7     0.8   0.4    L1
s8     2.6   9.5    L2
s9     3.7   7.1    L2
s10    2.7   8.3    L2

I want to randomly select 4 records from the above table such that 50 % that is 2 records have labels L1 and 2 records have labels L2 and looks like the following

s_key  C1    C2    labels
s1     0.2   0.1    L1
s2     0.3   0.3    L1
s3     0.25  0.32   L2
s10    2.7   8.3    L2

How can I do this in Tsql/Sql? Appreciate any input.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

What are the differences between Standard SQL and Transact-SQL?

In this article, we'll explain syntax differences between standard SQL and the Transact-SQL language dedicated to interacting with the SQL

Sum Time columns in SQL

I'm writing a query to calculate when the students check-in and check-out and how much time they spend at the GYM. I have a Checking Field that contains the check-in time and a check-out field that contains the check-out, and a Duration.

T-SQL Training using Real World Scenarios:Tricks of the Trade | Simpliv

T-SQL Training using Real World Scenarios:Tricks of the Trade