mercredi 27 avril 2016

Selecting N number of Random Records

I have 7200 rows of 29 users who attended unique request tickets in 10 different categories.

Out of them, I need to select N records for each and every Users.

Conditions :

  1. Out of N, 40 % rows should be those of a category X, Lets say Editorial.

  2. Remaining 60 % rows should be those using other than Category X

Using sqlite, I handled so far by trying 'DISTINCT' but is there a way to achieve the above?

select distinct * from report 
where category <> 'Editorial'
and 
name in (select distinct name from report)
GROUP By name
LIMIT (select count(distinct name) from report)

edit : I'm using python for rest of all the above operations. As its a large data, I preferred sqlite. If there's a way in python, I'm okie to learn about it.

Aucun commentaire:

Enregistrer un commentaire