与此Receive range of dates. If starting dating doesn't exist fetch range from the closest past date相关,我遇到了一个奇怪的问题。
这里的表HistoryPrices
是这样的:
| Date | Price |
|------------|-------|
| 2015-12-25 | 44.5 |
| 2016-01-01 | 90.5 |
| 2016-01-03 | 50.5 |
| 2016-01-04 | 45.6 |
| 2016-01-10 | 40.99 |
| 2016-01-15 | 50.5 |
| 2016-01-22 | 50.99 |
当我运行此查询时:
select *
from HistoryPrices
order by `date` desc
limit 1;
我得到了正确的行| 2016-01-22 | 50.99 |
。
当我跑这个时:
select '2016-01-22', Price
from HistoryPrices
order by `date` desc
limit 1;
也是正确的预期结果| 2016-01-22 | 50.99 |
这个查询:
select '2016-01-22' as xxx, Price
from HistoryPrices
order by `date` desc
limit 1;
然而,当我跑这个时:
select '2016-01-22' as `date`, Price
from HistoryPrices
order by `date` desc
limit 1;
我得到了这个结果| 2016-01-22 | 44.5 |
。我不知道为什么会这样。也许列别名和列名是相同的date
,那么当order by `date`
时,mysql不知道怎么做?但我无法证实这一点。
请问有人可以解释一下吗? 任何帮助将不胜感激。提前谢谢。
答案 0 :(得分:2)
MySQL允许在while True:
num = int(input("Enter a positive number to see if it's a prime number: "))
if num > 1:
break
elif num == 1:
print("1 is technically not a prime number.")
else:
print("Number cannot be negative- try again.")
for num1 in range(2,num):
div = num%num1
if div == 0:
print(num1,"is a divisor of",num,"... stopping.")
print(num,"is not a prime number.")
sys.exit()
else:
print(num1,"is NOT a divisor of",num,"... continuing")
print(num,"is a prime number!")
中引用列别名。如果您需要表名,请对列进行限定:
order by