【发布时间】:2018-12-26 04:34:20
【问题描述】:
假设我有桌子:
** Table**
---------------------------------------
ID Type Number Size Location
---------------------------------------
1 Apple 5 M A
2 Apple 4 S B
3 Banana 5 M B
4 Apple 7 S A
5 Pear 5 L C
6 Pear 5 M A
7 Apple 3 L A
8 Pear 2 M A
9 Banana 4 M B
我的程序是select.py [-t type] [-n number] [-s size] [-l location] (所有参数都是可选的。)
如果给出-t,那么它将运行“select * from table where Type= args.type”;
如果给出-n,那么它将运行“select * from table where Number= args.number”;
如果同时给出 -t 和 -n,那么它将运行“select * from table where Type= args.type 和 Number = args.number";
...
如果所有参数都给出,那么它将运行“select * from table where Type= args.type and Number = args.number and ... and ..”;
如何编写一个通用的 where 子句来涵盖所有上述可能的情况?
【问题讨论】:
-
请编辑您的问题,以便其他人更容易阅读。