SQL query - select max where a count greater than value

Gooey

I've got two tables with the following structure:

Question table

id int, 
question text, 
answer text, 
level int

Progress table

qid int, 
attempts int, 
completed boolean (qid means question id)

Now my questions is how to construct a query that selects the max level where the count of correct questions is greater than let's say 30.

I created this query, but it doesn't work and I don't know why.

SELECT MAX(Questions.level) 
FROM Questions, Progress 
WHERE Questions.id = Progress.qid AND Progress.completed = 1 
GROUP BY  Questions.id, Questions.level 
Having COUNT(*) >= 30

I would like to have it in one query as I suspect this is possible and probably the most 'optimized' way to query for it. Thanks for the help!

Dan Bracuk

This sort of construct will work. You can figure out the details.

select max(something) maxvalue
from SomeTables
join (select id, count(*) records
from ATable
group by id) temp on ATable.id = temp.id
where records >= 30

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL select from inner join where count greater than

From Dev

Select Count Where Values greater than 0 SQL Server

From Dev

SQL select from inner join where count greater than

From Dev

SQL Query to Bring Back where Row Count is Greater than 1

From Dev

SQL Query to Bring Back where Row Count is Greater than 1

From Dev

SQL - Select rows with values greater than max value for id and category

From Dev

SQL group by count where count greater than

From Dev

MySQL count rows where column value is same and select them where count is greater than 2

From Dev

Linq: Where count greater than value

From Dev

select count Max(value) with where

From Dev

SQL select if count on relation is greater than X?

From Dev

Select where no value is greater than X

From Dev

SQL Where clause use if value greater than

From Dev

An SQL query with a WHERE greater than a count, when another field is already in GROUP BY

From Dev

An SQL query with a WHERE greater than a count, when another field is already in GROUP BY

From Dev

Select Where Count() of multiple columns is greater than one

From Dev

Doctrine Query Builder Where Count of ManyToMany is greater than

From Dev

Doctrine Query Builder Where Count of ManyToMany is greater than

From Dev

filter groups where max value is greater than limit

From Dev

How to count rows of pivot table where value is greater than 0

From Dev

How to select where sum of fields is greater than a value in MongoDB

From Dev

sql select where (sum of 2 columns) is greater than X

From Dev

SQL Select rows where created_at is greater than a date

From Dev

SQL query: Select max value of subselect

From Dev

SQL : I search the good query with select max() and select count()

From Dev

complex sql query combining 'select max' and select count(*) queries

From Dev

SQL select MAX(COUNT)

From Dev

SQL Update Statement Where Value Must Be Greater Than the Previous Value But less Than the next

From Dev

MYSQL Select Count if greater than 0

Related Related

  1. 1

    SQL select from inner join where count greater than

  2. 2

    Select Count Where Values greater than 0 SQL Server

  3. 3

    SQL select from inner join where count greater than

  4. 4

    SQL Query to Bring Back where Row Count is Greater than 1

  5. 5

    SQL Query to Bring Back where Row Count is Greater than 1

  6. 6

    SQL - Select rows with values greater than max value for id and category

  7. 7

    SQL group by count where count greater than

  8. 8

    MySQL count rows where column value is same and select them where count is greater than 2

  9. 9

    Linq: Where count greater than value

  10. 10

    select count Max(value) with where

  11. 11

    SQL select if count on relation is greater than X?

  12. 12

    Select where no value is greater than X

  13. 13

    SQL Where clause use if value greater than

  14. 14

    An SQL query with a WHERE greater than a count, when another field is already in GROUP BY

  15. 15

    An SQL query with a WHERE greater than a count, when another field is already in GROUP BY

  16. 16

    Select Where Count() of multiple columns is greater than one

  17. 17

    Doctrine Query Builder Where Count of ManyToMany is greater than

  18. 18

    Doctrine Query Builder Where Count of ManyToMany is greater than

  19. 19

    filter groups where max value is greater than limit

  20. 20

    How to count rows of pivot table where value is greater than 0

  21. 21

    How to select where sum of fields is greater than a value in MongoDB

  22. 22

    sql select where (sum of 2 columns) is greater than X

  23. 23

    SQL Select rows where created_at is greater than a date

  24. 24

    SQL query: Select max value of subselect

  25. 25

    SQL : I search the good query with select max() and select count()

  26. 26

    complex sql query combining 'select max' and select count(*) queries

  27. 27

    SQL select MAX(COUNT)

  28. 28

    SQL Update Statement Where Value Must Be Greater Than the Previous Value But less Than the next

  29. 29

    MYSQL Select Count if greater than 0

HotTag

Archive