Select a column and assign it different percentages for its 2 rows (1 Viewer)

pantelis

New member
Local time
Today, 20:05
Joined
Mar 13, 2013
Messages
2
Hi there,

I got a database named Quiz and i want to make a query based on Questions
table.
Questions table got "question id", "title", "difficulty" and "chapter" as columns.
How is it possible to make a query that have just 20 questions selected and in that 20 questions,
the 40% would be difficulty "easy" and the rest 60% would be difficulty "hard".
I tried to find a way for it and in the end i couldnt do it.
I will appreciate it if you can help me.

Thanks.
Pantelis G.
 

JHB

Have been here a while
Local time
Today, 21:05
Joined
Jun 17, 2012
Messages
7,732
If it is not has to be random selected, use a UNION query, with top 8 and top 12.
60% of 20 = 12
 

PeterF

Registered User.
Local time
Today, 21:05
Joined
Jun 6, 2006
Messages
295
And if it need to be random record sort by randomizing like:
Code:
SELECT TOP 8 * FROM [Questions] ORDER BY rnd(INT(NOW*[question id])-NOW*id) WHERE difficulty = "Easy" ;
Union
SELECT TOP 12 * FROM [Questions] ORDER BY rnd(INT(NOW*[question id])-NOW*id) WHERE difficulty = "Hard" ;
The only prerequisite is that you have "Question ID" defined as AutoNumber. Although this generates a random set of records, they are not truely random in a mathematical sense, but should be sufficiently random for most uses.

Note: You should avoid the use of spaces and special characters in field, table and control names, it makes it harder to write code / query as you need the use of square braquets.
 

Users who are viewing this thread

Top Bottom