SQLite子查询语法/错误/与MySQL的区别
我的印象是这是有效的 SQLite 语法:
SELECT
*,
(SELECT amount AS target
FROM target_money
WHERE start_year <= p.bill_year
AND start_month <= p.bill_month
ORDER BY start_year ASC, start_month ASC
LIMIT 1) AS target
FROM payments AS p;
但我想它不是,因为 SQLite 返回此错误:
没有这样的列:p.bill_year
我引用 p.bill_year 的方式有什么问题?
是的,我确信表 payment 包含一列
bill_year 。我疯了还是这只是有效的 SQL 语法?它可以在 MySQL 中工作不是吗?我没有任何其他 SQL 存在,所以我无法测试其他 SQLite,但我认为 SQLite 非常标准。
I was under the impression this is valid SQLite syntax:
SELECT
*,
(SELECT amount AS target
FROM target_money
WHERE start_year <= p.bill_year
AND start_month <= p.bill_month
ORDER BY start_year ASC, start_month ASC
LIMIT 1) AS target
FROM payments AS p;
But I guess it's not, because SQLite returns this error:
no such column: p.bill_year
What's wrong with how I refer to p.bill_year?
Yes, I am positive table payments
hosts a column bill_year
. Am I crazy or is this just valid SQL syntax? It would work in MySQL wouldn't it?? I don't have any other SQL present so I can't test others, but I thought SQLite was quite standardlike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢,标记。
您的查询在 SQLite 中运行良好:
Thanks, Mark.
Your query works fine in SQLite:
它可以在 MySQL 中工作:
我想它也可以在 SQLite 中工作。我确信这里有人可以复制并复制粘贴上面的内容来验证它......
It works in MySQL:
I'd imagine that it would work in SQLite too. I'm sure someone here can copy & paste the above to verify it...
我做了一些测试来确认相关子查询不适用于 sqlite2,但适用于 sqlite3,这似乎是一种情况。问题是官方文档对此只字未提。 sqlite2 在某些奇怪的语法下支持相关子查询的可能性仍然很小。这就是我在不深入 sqlite2 源代码的情况下所能知道的。
I make some tests to confirm that correlated subqueries dosn't work on sqlite2, but works on sqlite3, and that seems to be a case. The problem is that official documentation says nothing about it. There is still a small possibility that correlated subqueries are supported in sqlite2 under some odd syntax. Thats all I can tell without getting into sqlite2 source code.