- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 nodeJs 中使用 sequelize,我有这段代码:
Time_Sheet_Details.findAll({
include: [
{
model: timesheetNotesSubcon,
required: false,
attributes:["note","file_name", "id", "working_hrs", "timestamp", "has_screenshot", "notes_category"]
},
{
model: Timesheet,
attributes:["id","leads_id","userid"],
include:[
{
model: Lead_Info, attributes:["id","fname","lname","email","hiring_coordinator_id","status"],
where: { hiring_coordinator_id : 326},
include:[{
model: adminInfoSchema,
required: false,
attributes:["admin_id","admin_fname", "admin_lname", "admin_email", "signature_contact_nos", "signature_company"],
}]
},
{model:Personal_Info,attributes:["userid","fname","lname","email"]}
],
}],
where: {
reference_date: filters.reference_date
},
order:[
["id","DESC"]
],
offset:((1-1)*30),
limit : 30,
}).then(function(foundObject){
willFulfillDeferred.resolve(foundObject);
});
结果查询是:
SELECT `timesheet_details`.*, `timesheet_notes_subcons`.`note` AS
`timesheet_notes_subcons.note`, `timesheet_notes_subcons`.`file_name` AS
`timesheet_notes_subcons.file_name`, `timesheet_notes_subcons`.`id` AS
`timesheet_notes_subcons.id`, `timesheet_notes_subcons`.`working_hrs` AS
`timesheet_notes_subcons.working_hrs`, `timesheet_notes_subcons`.`timestamp` AS
`timesheet_notes_subcons.timestamp`, `timesheet_notes_subcons`.`has_screenshot` AS
`timesheet_notes_subcons.has_screenshot`,
`timesheet_notes_subcons`.`notes_category` AS
`timesheet_notes_subcons.notes_category`, `timesheet.lead`.`id` AS
`timesheet.lead.id`, `timesheet.lead`.`fname` AS `timesheet.lead.fname`,
`timesheet.lead`.`lname` AS `timesheet.lead.lname`,
`timesheet.lead`.`email` AS `timesheet.lead.email`,
`timesheet.lead`.`hiring_coordinator_id` AS
`timesheet.lead.hiring_coordinator_id`, `timesheet.lead`.`status` AS
`timesheet.lead.status`, `timesheet.lead.admin`.`admin_id` AS
`timesheet.lead.admin.admin_id`, `timesheet.lead.admin`.`admin_fname` AS
`timesheet.lead.admin.admin_fname`, `timesheet.lead.admin`.`admin_lname` AS
`timesheet.lead.admin.admin_lname`, `timesheet.lead.admin`.`admin_email` AS
`timesheet.lead.admin.admin_email`,
`timesheet.lead.admin`.`signature_contact_nos` AS
`timesheet.lead.admin.signature_contact_nos`,
`timesheet.lead.admin`.`signature_company` AS
`timesheet.lead.admin.signature_company`, `timesheet.personal`.`userid` AS
`timesheet.personal.userid`, `timesheet.personal`.`fname` AS
`timesheet.personal.fname`, `timesheet.personal`.`lname` AS
`timesheet.personal.lname`, `timesheet.personal`.`email` AS
`timesheet.personal.email` FROM (SELECT `timesheet_details`.`id`,
`timesheet_details`.`timesheet_id`, `timesheet_details`.`day`,
`timesheet_details`.`total_hrs`, `timesheet_details`.`adj_hrs`,
`timesheet_details`.`regular_rostered`, `timesheet_details`.`hrs_charged_to_client`,
`timesheet_details`.`diff_charged_to_client`,
`timesheet_details`.`hrs_to_be_subcon`,
`timesheet_details`.`diff_paid_vs_adj_hrs`, `timesheet_details`.`status`,
`timesheet_details`.`reference_date`, `timesheet`.`id` AS `timesheet.id`,
`timesheet`.`leads_id` AS `timesheet.leads_id`, `timesheet`.`userid` AS
`timesheet.userid` FROM `timesheet_details` AS `timesheet_details`
LEFT OUTER JOIN `timesheet` AS `timesheet`
ON `timesheet_details`.`timesheet_id` = `timesheet`.`id`
WHERE (`timesheet_details`.`reference_date` >= '2016-04-23 16:00:00'
AND `timesheet_details`.`reference_date` < '2017-05-02 15:59:59')
ORDER BY `timesheet_details`.`id` DESC LIMIT 0, 30) AS
`timesheet_details` LEFT OUTER JOIN `timesheet_notes_subcon` AS
`timesheet_notes_subcons` ON `timesheet_details`.`id` =
`timesheet_notes_subcons`.`timesheet_details_id`
INNER JOIN `leads` AS `timesheet.lead` ON `timesheet.leads_id` =
`timesheet.lead`.`id` AND `timesheet.lead`.`hiring_coordinator_id` = 326
LEFT OUTER JOIN `admin` AS `timesheet.lead.admin` ON
`timesheet.lead`.`hiring_coordinator_id` =
`timesheet.lead.admin`.`admin_id`
LEFT OUTER JOIN `personal` AS `timesheet.personal` ON `timesheet.userid`
= `timesheet.personal`.`userid` ORDER BY `timesheet_details`.`id` DESC;
如您所见,LIMIT 0, 30
不在查询的末尾。这对我来说是个问题,因为该查询将不返回任何内容,并且限制和偏移量应该在查询的末尾,如下所示:
SELECT `timesheet_details`.*, `timesheet_notes_subcons`.`note` AS
`timesheet_notes_subcons.note`, `timesheet_notes_subcons`.`file_name` AS
`timesheet_notes_subcons.file_name`, `timesheet_notes_subcons`.`id` AS
`timesheet_notes_subcons.id`, `timesheet_notes_subcons`.`working_hrs` AS
`timesheet_notes_subcons.working_hrs`,
`timesheet_notes_subcons`.`timestamp` AS
`timesheet_notes_subcons.timestamp`,
`timesheet_notes_subcons`.`has_screenshot` AS
`timesheet_notes_subcons.has_screenshot`,
`timesheet_notes_subcons`.`notes_category` AS
`timesheet_notes_subcons.notes_category`, `timesheet.lead`.`id` AS
`timesheet.lead.id`, `timesheet.lead`.`fname` AS `timesheet.lead.fname`,
`timesheet.lead`.`lname` AS `timesheet.lead.lname`,
`timesheet.lead`.`email` AS `timesheet.lead.email`,
`timesheet.lead`.`hiring_coordinator_id` AS
`timesheet.lead.hiring_coordinator_id`, `timesheet.lead`.`status` AS
`timesheet.lead.status`, `timesheet.lead.admin`.`admin_id` AS
`timesheet.lead.admin.admin_id`, `timesheet.lead.admin`.`admin_fname` AS
`timesheet.lead.admin.admin_fname`, `timesheet.lead.admin`.`admin_lname`
AS `timesheet.lead.admin.admin_lname`,
`timesheet.lead.admin`.`admin_email` AS
`timesheet.lead.admin.admin_email`,
`timesheet.lead.admin`.`signature_contact_nos` AS
`timesheet.lead.admin.signature_contact_nos`,
`timesheet.lead.admin`.`signature_company` AS
`timesheet.lead.admin.signature_company`, `timesheet.personal`.`userid`
AS `timesheet.personal.userid`, `timesheet.personal`.`fname` AS
`timesheet.personal.fname`, `timesheet.personal`.`lname` AS
`timesheet.personal.lname`, `timesheet.personal`.`email` AS
`timesheet.personal.email` FROM (SELECT `timesheet_details`.`id`,
`timesheet_details`.`timesheet_id`, `timesheet_details`.`day`,
`timesheet_details`.`total_hrs`, `timesheet_details`.`adj_hrs`,
`timesheet_details`.`regular_rostered`,
`timesheet_details`.`hrs_charged_to_client`,
`timesheet_details`.`diff_charged_to_client`,
`timesheet_details`.`hrs_to_be_subcon`,
`timesheet_details`.`diff_paid_vs_adj_hrs`,
`timesheet_details`.`status`, `timesheet_details`.`reference_date`,
`timesheet`.`id` AS `timesheet.id`, `timesheet`.`leads_id` AS
`timesheet.leads_id`, `timesheet`.`userid` AS `timesheet.userid`
FROM `timesheet_details` AS `timesheet_details`
LEFT OUTER JOIN `timesheet` AS `timesheet` ON
`timesheet_details`.`timesheet_id` = `timesheet`.`id`
WHERE (`timesheet_details`.`reference_date` >= '2016-04-23 16:00:00'
AND `timesheet_details`.`reference_date` < '2017-05-02 15:59:59')
ORDER BY `timesheet_details`.`id` DESC) AS `timesheet_details`
LEFT OUTER JOIN `timesheet_notes_subcon` AS `timesheet_notes_subcons` ON
`timesheet_details`.`id` =
`timesheet_notes_subcons`.`timesheet_details_id` INNER JOIN `leads` AS
`timesheet.lead` ON `timesheet.leads_id` = `timesheet.lead`.`id` AND
`timesheet.lead`.`hiring_coordinator_id` = 326 LEFT OUTER JOIN `admin` AS
`timesheet.lead.admin` ON `timesheet.lead`.`hiring_coordinator_id` =
`timesheet.lead.admin`.`admin_id` LEFT OUTER JOIN `personal` AS
`timesheet.personal` ON `timesheet.userid` =
`timesheet.personal`.`userid` ORDER BY `timesheet_details`.`id` DESC
LIMIT 0, 30;
我的代码有什么地方做错了吗?我是否放错了订单和限制?
最佳答案
找到了我的问题的答案,我只需要添加 subQuery = false
这样限制和偏移就不会被评估为子查询。并且偏移量和限制也在查询的末尾。
offset:((page-1)*limit),
limit : limit,
subQuery:false
关于javascript - Sequelize limit 和 offset 查询中不正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43729254/
好吧,我对我的页面发生的事情有点困惑。我在底部有页码, table 上摆满了 23 种不同的元素。 每个页面应一次显示 5 个项目。我显示的页面发送了一个带有 pagenumber = 不管怎样的 g
几周前我开始学习 Ada。我知道 limited 在某些情况下声明了一个有限类型,不允许复制对象 来自 Ada Reference Manual 2012 7.5 1/2 A limited type
我想按 DESC 选择日期并限制为最后 3 个,然后我需要基本上翻转最后 3 个结果,以便它们按 ASC 排序 任何帮助将不胜感激,我正在使用 postgresql 最佳答案 SELECT * FRO
SELECT * FROM mm_tfs WHERE product_slug LIKE '%football%' AND schoolid = '8' AND category_id ='2
SELECT * FROM mm_tfs WHERE product_slug LIKE '%football%' AND schoolid = '8' AND category_id ='2
我正在尝试访问按“日期”键排序的表中恒定数量的最新文档。请注意,不幸的是,日期是被实现的(不是由我......),使得该值设置为字符串,例如“2014-01-14”,或者有时“2014-01-14 2
我目前正在使用具有限制 cpu、限制内存以及保留 cpu 和内存的 Docker Swarm。 完成测试后,我想删除这些配置。我找不到任何有关如何删除这些的文章。 是否有办法通过更新来删除这些设置而不
我目前正在使用具有限制 cpu、限制内存以及保留 cpu 和内存的 Docker Swarm。 完成测试后,我想删除这些配置。我找不到任何有关如何删除这些的文章。 是否有办法通过更新来删除这些设置而不
我必须对我的数据应用分页。我通过复杂的连接查询获取数据,没有任何子查询,只有简单的连接。 假设这个查询[这是一个非常简单的查询,我有一个比这个复杂的查询] SELECT states.state
我经常制作条形图,并将条形图的值额外包含为注释 (geom_text)。通常,我更喜欢这些值右对齐(与将标签放在条形顶部相反)。在绘制多面条形图时,我将这些值放在每个组中的最大值(我之前计算过)加上我
delivery-limit 和 x-delivery-limit 有什么区别? 当我将 x-delivery-limit 设置为 RabbitMQ 队列参数时,我可以看到它限制了我的消息重新排队尝试
delivery-limit 和 x-delivery-limit 有什么区别? 当我将 x-delivery-limit 设置为 RabbitMQ 队列参数时,我可以看到它限制了我的消息重新排队尝试
我正在使用 PostgreSQL 9.3。这应该在具有 100,000 多行的任何表上重现。 EXPLAIN ANALYZE 显示使用 LIMIT 2 扫描了更多行,但我不明白为什么。 限制 1: E
我正在尝试找出是否可以在 PHP 中全局设置和取消设置 MySQL 结果的默认限制。 一些可能看起来像的伪代码: $pdo->prepare('SELECT * FROM example'); $pd
我有下面的代码片段表 在这里我必须对投票前 3 个值求和。 假设 product_id 3030 vote 列的总和为 8.1 和 3671 总和 是 5.2 在这里,我必须获得前 3 个 produ
我正在使用全文搜索来提取行。 我根据分数 (ORDER BY SCORE) 对行进行排序,然后在前 20 行 (LIMIT 20) 中,我想对结果集进行兰德 (RAND)。 因此,对于任何特定的搜索词
帮助创建搜索条件 SELECT * FROM mlt_adr_city WHERE name LIKE "Text%" AND region_id = 59 AND id <> 0 IF (name
MySQL 查询示例: SELECT message_id, message_text FROM messages LIMIT 0 , 30 我得到的这个提示是错误的: HIN
我注意到如果我将查询限制为 1 个而不是 5 个,速度会急剧下降。 SELECT he. * FROM homematic_events he WHERE he.homematic_devices_i
我需要从我的表中获取最后一个 ID,以便我可以在另一个函数中使用它我在我的存储库中创建了这个函数,但我没有工作,它显示了一个错误: [Syntax Error] line 0, col 60: Err
我是一名优秀的程序员,十分优秀!