作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Sequalize ORM 从数据库中获取数据。我有以下查询要执行,它在 Postgres DB 中运行良好,我想对其进行均衡,具体来说,我的查询与如何均衡 FROM 子句中的子查询部分有关。
SELECT
"users"."id",
"users"."user_id" AS "peopleId",
"users"."first_name" AS "firstName",
"users"."last_name" AS "lastName",
"users"."email",
"users"."mobile",
"users"."status"
FROM (select * from users where address_id in (select addresses_id from location_view where location = 'Some, Location, India')) as "users"
LEFT OUTER JOIN "addresses" AS "addresses" ON "users"."address_id" = "addresses"."id"
LEFT OUTER JOIN "countries" AS "addresses->countries" ON "addresses"."country_id" = "addresses->countries"."id"
LEFT OUTER JOIN "work_info" AS "work_info" ON "users"."work_info_id" = "work_info"."id"
WHERE
"users"."status" = 'Active'
ORDER BY
"users"."first_name" ASC
LIMIT
5 OFFSET 0;
我知道我们确实有 Sequalize.query 和文字方法来实现这一点,我可以直接以原始格式指定我的子查询,但是无论我用谷歌搜索出什么例子,基本上都提供了一种如何在 WHERE 或 select 中编写原始查询的方法属性子查询条件。
最佳答案
也许您根本不需要子查询?这是相同的查询,但已扁平化。
SELECT
"users"."id",
"users"."user_id" AS "peopleId",
"users"."first_name" AS "firstName",
"users"."last_name" AS "lastName",
"users"."email",
"users"."mobile",
"users"."status"
FROM "users"
LEFT OUTER JOIN location_view lv on "users".address_id = lv.addresses_id
LEFT OUTER JOIN "addresses" AS "addresses" ON "users"."address_id" = "addresses"."id"
LEFT OUTER JOIN "countries" AS "addresses->countries" ON "addresses"."country_id" = "addresses->countries"."id"
LEFT OUTER JOIN "work_info" AS "work_info" ON "users"."work_info_id" = "work_info"."id"
WHERE
"users"."status" = 'Active' AND lv.location = 'Some, Location, India'
ORDER BY
"users"."first_name" ASC
LIMIT
5 OFFSET 0;
为了尽可能接近您的查询,我保留了双引号,但请注意,仅当名称包含大写字母和/或非字母数字字符时才需要双引号。
关于mysql - 在Sequelize的FROM子句中指定子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64893663/
在我的应用程序中,我想检测手指按在屏幕上的类型。触摸类型可能是单点触摸或多点触摸。我搜索了很多,但找不到任何东西。 有什么方法可以找到类型吗? 最佳答案 不可能知道哪个手指在某个点,但您肯定可以获得每
以下代码是我一直在尝试用于多点触控的代码。手指一设置正确并在我拖动手指时四处移动。当我触摸并松开手指时,第二个手指出现并消失,但它永远不会移动。知道有什么问题吗? 我已阅读 developers bl
我是一名优秀的程序员,十分优秀!