简体   繁体   中英

Conditionally creating a list of numbers in Access SQL

This is a homework task for Microsoft Access 2010.
How to create a query that will return a list of numbers from 1 to 18? Though on one condition, that the list of numbers will not contain any number that exists in table A.

So for example. Table A has 1, 5, 10, 8, and 16. Therefore, the query will only return this list of numbers (2, 3, 4, 6, 7, 9, 11, 12, 13, 14, 15, 17, 18)

Would anyone be kind enough to shed some pointers? Thanks.

SQL is a set-based language. So you are always working with intersections, unions, complements, etc.

Consider that Table A could be completely empty. In this case you need to return all the numbers from 1 to 18. You are going to need to get these numbers from somewhere. (Hint, how about creating another table?)

Once you can write a query returning all the numbers from 1 to 18, you can start thinking about getting all the numbers from 1 to 18 EXCEPT those in table A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM