MySQL 上的选择查询极慢

2024-04-14

我试图理解为什么选择查询在我的笔记本电脑上运行得非常快,而在服务器上运行得非常慢。查询需要1.388在笔记本电脑上运行的秒数49.670服务器上的秒数。两种模式是相同的,因为我已从笔记本电脑导出该模式并将其导入服务器。两者都在 WAMP 2.0 上运行 MySQL 5.1.36。

SQL Dump

https://db.tt/4TvuOWbD https://db.tt/4TvuOWbD

Query

SELECT form.id                                                                                     AS 'Form ID',
       DATE_FORMAT(form.created_on, '%d %b %Y')                                                    AS 'Created On - Date',
       DATE_FORMAT(form.created_on, '%h:%i %p')                                                    AS 'Created On - Time',
       department.name                                                                             AS 'Department',
       section.name                                                                                AS 'Section',
       reporting_to_1.id                                                                           AS 'Reporting To 1 - System ID',
       reporting_to_1.real_name                                                                    AS 'Reporting To 1 - Name',
       reporting_to_1_department.name                                                              AS 'Reporting To 1 - Department',
       reporting_to_1_section.name                                                                 AS 'Reporting To 1 - Section',
       CONVERT(IFNULL(reporting_to_2.id, '') USING utf8)                                           AS 'Reporting To 2 - System ID',
       IFNULL(reporting_to_2.real_name, '')                                                        AS 'Reporting To 2 - Name',
       IFNULL(reporting_to_2_department.name, '')                                                  AS 'Reporting To 2 - Department',
       IFNULL(reporting_to_2_section.name, '')                                                     AS 'Reporting To 2 - Section',
       form_type.type                                                                              AS 'Form Type',
       CONVERT(IF(form.customer_number = 0, '-', form.customer_number) USING utf8)                 AS 'Customer Number', 
       form.customer_name                                                                          AS 'Customer Name',
       form.customer_contract                                                                      AS 'Customer Contract No.',
       DATE_FORMAT(form.action_date, '%d %b %Y')                                                   AS 'Action - On Date',
       CONCAT('http://cns', attachment_1.path, '/', attachment_1.filename_generated)               AS 'Attachment - 1',
       CONCAT('http://cns', attachment_2.path, '/', attachment_2.filename_generated)               AS 'Attachment - 2',
       agent.name                                                                                  AS 'Agent - Name',
       agent.tag                                                                                   AS 'Agent - Tag',
       agent.type                                                                                  AS 'Agent - Type',
       CONVERT(IFNULL(agent_teamleader.real_name, '') USING utf8)                                  AS 'Agent - Team Leader - Name',
       creator.id                                                                                  AS `creator id`, 
       creator.real_name                                                                           AS `creator full name`, 
       CONVERT(IFNULL(authorizing_teamleader_user.id, '') USING utf8)                              AS `processed by - team leader - system id`, 
       IFNULL(authorizing_teamleader_user.real_name, '')                                           AS `processed by - team leader - name`, 
       CONVERT(IFNULL(authorizing_teamleader_user.employee_id, '') USING utf8)                     AS `processed by - team leader - employee id`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_teamleader.action_date, '%d %b %Y'), '') USING utf8) AS `processed on - team leader - date`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_teamleader.action_date, '%h:%i %p'), '') USING utf8) AS `processed on - team leader - time`, 
       CONVERT(IFNULL(authorizing_manager_user.id, '') USING utf8)                                 AS `processed by - manager - system id`, 
       IFNULL(authorizing_manager_user.real_name, '')                                              AS `processed by - manager - name`, 
       CONVERT(IFNULL(authorizing_manager_user.employee_id, '') USING utf8)                        AS `processed by - manager - employee id`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_manager.action_date, '%d %b %Y'), '') USING utf8)    AS `processed on - manager - date`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_manager.action_date, '%h:%i %p'), '') USING utf8)    AS `processed on - manager - time`, 
       CONVERT(IFNULL(authorizing_director_user.id, '') USING utf8)                                AS `processed by - director - system id`, 
       IFNULL(authorizing_director_user.real_name, '')                                             AS `processed by - director - name`, 
       CONVERT(IFNULL(authorizing_director_user.employee_id, '') USING utf8)                       AS `processed by - director - employee id`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_director.action_date, '%d %b %Y'), '') USING utf8)   AS `processed on - director - date`, 
       CONVERT(IFNULL(DATE_FORMAT(authorizing_director.action_date, '%h:%i %p'), '') USING utf8)   AS `processed on - director - time`, 
       status.name                                                                                 AS `status`,
       CONVERT(IF(status.name = 'Pending', '', user_status_by.id) USING utf8)                      AS `status by - system id`, 
       IFNULL(user_status_by.real_name, '')                                                        AS `status by - name`, 
       CONVERT(IFNULL(user_status_by.employee_id, '') USING utf8)                                  AS `status by - employee id`, 
       IFNULL(user_status_by_role.name, '')                                                        AS `status by - position`, 
       CONVERT(IFNULL(DATE_FORMAT(form.status_on, '%d %b %Y'), '') USING utf8)                     AS `status on - date`, 
       CONVERT(IFNULL(DATE_FORMAT(form.status_on, '%h:%i %p'), '') USING utf8)                     AS `status on - time`, 
       CONCAT('http://cns/pdf/', form.pdf)                                                         AS `pdf`
FROM   forms AS form
       JOIN (sections AS section, 
            departments AS department) 
         ON form.section_id = section.id 
             AND section.department_id = department.id 
       JOIN (users AS reporting_to_1, 
            sections AS reporting_to_1_section, 
            departments AS reporting_to_1_department)
         ON reporting_to_1.id = form.reporting_to_1 
             AND reporting_to_1.section_id = reporting_to_1_section.id 
             AND reporting_to_1_section.department_id = reporting_to_1_department.id 
       LEFT JOIN (users AS reporting_to_2, sections AS reporting_to_2_section, 
                 departments AS reporting_to_2_department)
         ON reporting_to_2.id = form.reporting_to_2 
             AND reporting_to_2.section_id = reporting_to_2_section.id 
             AND reporting_to_2_section.department_id = reporting_to_2_department.id 
       JOIN form_type 
         ON form.type = form_type.id 
       LEFT JOIN attachments AS attachment_1 
         ON form.id = attachment_1.form 
             AND attachment_1.id = ( SELECT min(id) 
                                     FROM   attachments 
                                     WHERE  form = form.id) 
       LEFT JOIN attachments AS attachment_2 
         ON form.id = attachment_2.form 
             AND attachment_2.id = ( SELECT max(id) 
                                     FROM   attachments 
                                     WHERE  form = form.id) 
       LEFT JOIN (agents AS agent,
                 users AS agent_teamleader,
                 branches AS branch) 
         ON form.id = agent.form_id 
             AND agent_teamleader.id = agent.teamleader_id 
             AND branch.id = agent.branch_id 
       JOIN users AS creator 
          ON form.user_id = creator.id 
       LEFT JOIN (authorizers AS authorizing_teamleader,
                 users AS authorizing_teamleader_user) 
          ON authorizing_teamleader.form_id = form.id 
             AND authorizing_teamleader_user.id = authorizing_teamleader.`from` 
             AND authorizing_teamleader_user.role = 't' 
       LEFT JOIN (authorizers AS authorizing_manager,
                 users AS authorizing_manager_user) 
          ON authorizing_manager.form_id = form.id 
             AND authorizing_manager_user.id = authorizing_manager.`from` 
             AND authorizing_manager_user.role = 'm' 
       LEFT JOIN (authorizers AS authorizing_director,
                 users AS authorizing_director_user) 
          ON authorizing_director.form_id = form.id 
             AND authorizing_director_user.id = authorizing_director.`from` 
             AND authorizing_director_user.role = 'd' 
       JOIN status 
          ON form.status = status.id 
       LEFT JOIN (users AS user_status_by,
                 roles AS user_status_by_role) 
          ON user_status_by.id = form.status_by_user_id 
             AND user_status_by_role.id = user_status_by.role 
GROUP  BY form.id 
ORDER  BY form.id DESC 
LIMIT 0, 100

解释扩展 - 服务器

+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+-------------+---------+------------------------------------------+------+----------+---------------------------------+
| id |    select_type     |            table            |  type  |                         possible_keys                          |     key     | key_len |                   ref                    | rows | filtered |              Extra              |
+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+-------------+---------+------------------------------------------+------+----------+---------------------------------+
|  1 | PRIMARY            | section                     | ALL    | PRIMARY,IDX_DEPARTMENT                                         |             |         |                                          |   18 |      100 | Using temporary; Using filesort |
|  1 | PRIMARY            | department                  | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.section.department_id                |    1 |      100 |                                 |
|  1 | PRIMARY            | form                        | ref    | IDX_USER_ID,IDX_REPORTING_TO_1,IDX_SECTION,IDX_TYPE,IDX_STATUS | IDX_SECTION |       4 | cns.section.id                           |  528 |      100 |                                 |
|  1 | PRIMARY            | status                      | eq_ref | PRIMARY                                                        | PRIMARY     |       3 | cns.form.status                          |    1 |      100 |                                 |
|  1 | PRIMARY            | form_type                   | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.form.type                            |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_teamleader      | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_teamleader_user | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY     |       4 | cns.authorizing_teamleader.from          |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_manager         | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_manager_user    | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY     |       4 | cns.authorizing_manager.from             |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_director        | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 |                                 |
|  1 | PRIMARY            | authorizing_director_user   | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY     |       4 | cns.authorizing_director.from            |    1 |      100 |                                 |
|  1 | PRIMARY            | attachment_1                | eq_ref | PRIMARY,IDX_FORM_ID                                            | PRIMARY     |       4 | func                                     |    1 |      100 |                                 |
|  1 | PRIMARY            | attachment_2                | eq_ref | PRIMARY,IDX_FORM_ID                                            | PRIMARY     |       4 | func                                     |    1 |      100 |                                 |
|  1 | PRIMARY            | agent                       | ref    | IDX_FORM_ID,IDX_BRANCH_ID,IDX_TEAMLEADER_ID                    | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 |                                 |
|  1 | PRIMARY            | agent_teamleader            | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.agent.teamleader_id                  |    1 |      100 |                                 |
|  1 | PRIMARY            | branch                      | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.agent.branch_id                      |    1 |      100 | Using index                     |
|  1 | PRIMARY            | reporting_to_1              | eq_ref | PRIMARY,IDX_SECTION                                            | PRIMARY     |       4 | cns.form.reporting_to_1                  |    1 |      100 |                                 |
|  1 | PRIMARY            | reporting_to_2              | eq_ref | PRIMARY,IDX_SECTION                                            | PRIMARY     |       4 | cns.form.reporting_to_2                  |    1 |      100 |                                 |
|  1 | PRIMARY            | reporting_to_2_section      | eq_ref | PRIMARY,IDX_DEPARTMENT                                         | PRIMARY     |       4 | cns.reporting_to_2.section_id            |    1 |      100 |                                 |
|  1 | PRIMARY            | reporting_to_2_department   | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.reporting_to_2_section.department_id |    1 |      100 |                                 |
|  1 | PRIMARY            | creator                     | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.form.user_id                         |    1 |      100 |                                 |
|  1 | PRIMARY            | reporting_to_1_section      | eq_ref | PRIMARY,IDX_DEPARTMENT                                         | PRIMARY     |       4 | cns.reporting_to_1.section_id            |    1 |      100 |                                 |
|  1 | PRIMARY            | reporting_to_1_department   | eq_ref | PRIMARY                                                        | PRIMARY     |       4 | cns.reporting_to_1_section.department_id |    1 |      100 |                                 |
|  1 | PRIMARY            | user_status_by              | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY     |       4 | cns.form.status_by_user_id               |    1 |      100 |                                 |
|  1 | PRIMARY            | user_status_by_role         | eq_ref | PRIMARY                                                        | PRIMARY     |       3 | cns.user_status_by.role                  |    1 |      100 |                                 |
|  3 | DEPENDENT SUBQUERY | attachments                 | ref    | IDX_FORM_ID                                                    | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 | Using index                     |
|  2 | DEPENDENT SUBQUERY | attachments                 | ref    | IDX_FORM_ID                                                    | IDX_FORM_ID |       4 | cns.form.id                              |    1 |      100 | Using index                     |
+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+-------------+---------+------------------------------------------+------+----------+---------------------------------+

解释扩展 - 笔记本电脑

+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+---------------+---------+------------------------------------------+------+----------+----------------------------------------------+
| id |    select_type     |            table            |  type  |                         possible_keys                          |      key      | key_len |                   ref                    | rows | filtered |                    Extra                     |
+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+---------------+---------+------------------------------------------+------+----------+----------------------------------------------+
|  1 | PRIMARY            | form_type                   | index  | PRIMARY                                                        | IDX_FORM_TYPE |     137 |                                          |    2 |      100 | Using index; Using temporary; Using filesort |
|  1 | PRIMARY            | form                        | ref    | IDX_USER_ID,IDX_REPORTING_TO_1,IDX_SECTION,IDX_TYPE,IDX_STATUS | IDX_TYPE      |       4 | cns.form_type.id                         | 1443 |      100 |                                              |
|  1 | PRIMARY            | status                      | eq_ref | PRIMARY                                                        | PRIMARY       |       3 | cns.form.status                          |    1 |      100 |                                              |
|  1 | PRIMARY            | section                     | eq_ref | PRIMARY,IDX_DEPARTMENT                                         | PRIMARY       |       4 | cns.form.section_id                      |    1 |      100 |                                              |
|  1 | PRIMARY            | department                  | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.section.department_id                |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_teamleader      | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_teamleader_user | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY       |       4 | cns.authorizing_teamleader.from          |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_manager         | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_manager_user    | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY       |       4 | cns.authorizing_manager.from             |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_director        | ref    | IDX_FORM_ID,IDX_FROM_USER_ID                                   | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 |                                              |
|  1 | PRIMARY            | authorizing_director_user   | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY       |       4 | cns.authorizing_director.from            |    1 |      100 |                                              |
|  1 | PRIMARY            | attachment_1                | eq_ref | PRIMARY,IDX_FORM_ID                                            | PRIMARY       |       4 | func                                     |    1 |      100 |                                              |
|  1 | PRIMARY            | attachment_2                | eq_ref | PRIMARY,IDX_FORM_ID                                            | PRIMARY       |       4 | func                                     |    1 |      100 |                                              |
|  1 | PRIMARY            | agent                       | ref    | IDX_FORM_ID,IDX_BRANCH_ID,IDX_TEAMLEADER_ID                    | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 |                                              |
|  1 | PRIMARY            | agent_teamleader            | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.agent.teamleader_id                  |    1 |      100 |                                              |
|  1 | PRIMARY            | branch                      | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.agent.branch_id                      |    1 |      100 | Using index                                  |
|  1 | PRIMARY            | reporting_to_1              | eq_ref | PRIMARY,IDX_SECTION                                            | PRIMARY       |       4 | cns.form.reporting_to_1                  |    1 |      100 |                                              |
|  1 | PRIMARY            | reporting_to_2              | eq_ref | PRIMARY,IDX_SECTION                                            | PRIMARY       |       4 | cns.form.reporting_to_2                  |    1 |      100 |                                              |
|  1 | PRIMARY            | reporting_to_2_section      | eq_ref | PRIMARY,IDX_DEPARTMENT                                         | PRIMARY       |       4 | cns.reporting_to_2.section_id            |    1 |      100 |                                              |
|  1 | PRIMARY            | reporting_to_2_department   | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.reporting_to_2_section.department_id |    1 |      100 |                                              |
|  1 | PRIMARY            | creator                     | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.form.user_id                         |    1 |      100 |                                              |
|  1 | PRIMARY            | reporting_to_1_section      | eq_ref | PRIMARY,IDX_DEPARTMENT                                         | PRIMARY       |       4 | cns.reporting_to_1.section_id            |    1 |      100 |                                              |
|  1 | PRIMARY            | reporting_to_1_department   | eq_ref | PRIMARY                                                        | PRIMARY       |       4 | cns.reporting_to_1_section.department_id |    1 |      100 |                                              |
|  1 | PRIMARY            | user_status_by              | eq_ref | PRIMARY,IDX_ROLE                                               | PRIMARY       |       4 | cns.form.status_by_user_id               |    1 |      100 |                                              |
|  1 | PRIMARY            | user_status_by_role         | eq_ref | PRIMARY                                                        | PRIMARY       |       3 | cns.user_status_by.role                  |    1 |      100 |                                              |
|  3 | DEPENDENT SUBQUERY | attachments                 | ref    | IDX_FORM_ID                                                    | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 | Using index                                  |
|  2 | DEPENDENT SUBQUERY | attachments                 | ref    | IDX_FORM_ID                                                    | IDX_FORM_ID   |       4 | cns.form.id                              |    1 |      100 | Using index                                  |
+----+--------------------+-----------------------------+--------+----------------------------------------------------------------+---------------+---------+------------------------------------------+------+----------+----------------------------------------------+

Model

笔记本电脑规格

操作系统:Microsoft Windows 7 Professional,处理器:Intel® Core™ i7-4600M 处理器(4M 缓存,高达 3.60 GHz),内存:8GB

服务器规格

操作系统:Microsoft Windows 2008 Standard SP2,处理器:Intel® Xeon® 处理器 X5570(8M 高速缓存,2.93 GHz,6.40 GT/s Intel® QPI),内存:4GB

故障排除

1.将两个数据库中所有表的引擎从 InnoDB 更改为 MyISAM 并进行优化。花了89.435在服务器上运行的秒数和57.252笔记本电脑上的秒数。与笔记本电脑相比,笔记本电脑仍然更快,但速度非常慢1.388使用 InnoDB 引擎的秒查询时间。


也许在将数据库从一台机器传输到另一台机器后,表中的索引没有被重建(我以前经历过这种情况)。你必须手动告诉MySQL重建索引。如果我没记错的话,您可以使用 OPTIMIZE 查询来实现

优化表your_table

不存在索引会显着减慢查询速度,尽管您遇到的差异可能太大而无法用此问题来解释。 就像之前的评论一样,您可以发布您的表格/查询吗?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MySQL 上的选择查询极慢 的相关文章

  • SQL Server Like 查询不区分大小写

    Query SELECT from Table 2 WHERE name like Joe Output 1 100 Joe 2 200 JOE 3 300 jOE 4 400 joe 为什么不区分大小写 Problem 查询不区分大小写
  • 如何编写可以补偿拼写错误数据的 MySQL 搜索?

    有没有什么方法可以编写一个 MySQL 搜索来弥补用户在拼写等方面的错误 作为随机示例 有人可能会输入 电子邮件受保护 cdn cgi l email protection代替 电子邮件受保护 cdn cgi l email protect
  • 如何比较行内的重叠值?

    我似乎对这个 SQL 查询有问题 SELECT FROM appts WHERE timeStart gt timeStart AND timeEnd lt timeEnd AND dayappt boatdate 时间格式为军用时间 物流
  • 唯一约束与唯一索引?

    之间有区别吗 CREATE TABLE p product no integer name text UNIQUE price numeric and CREATE TABLE p product no integer name text
  • 如何将 sql 数据输出到 QCalendarWidget

    我希望能够在日历小部件上突出显示 SQL 数据库中的一天 就像启动程序时突出显示当前日期一样 在我的示例中 它是红色突出显示 我想要发生的是 当用户按下突出显示的日期时 数据库中日期旁边的文本将显示在日历下方的标签上 这是我使用 QT De
  • 如何将事物的组合映射到关系数据库?

    我有一个表 其记录代表某些对象 为了简单起见 我假设该表只有一列 这是唯一的ObjectId 现在我需要一种方法来存储该表中的对象组合 组合必须是唯一的 但可以是任意长度 例如 如果我有ObjectIds 1 2 3 4 我想存储以下组合
  • 创建日期范围表

    我正在编写一份需要显示每天值的报告 我有查询的开始日期和结束日期 但我希望避免丢失日期 以防表不包含特定日期的值 我正在考虑创建一个基本日期范围表 其中包含开始和结束之间的所有日期 然后将其与数据表左连接以显示每一天的值 我找到了一些适用于
  • SQL 约束最小值/最大值?

    有没有办法为数字字段设置 SQL 约束 最小值应为 1234 最大值应为 4523 SQL Server 语法为the check约束 http technet microsoft com en us library ms179491 as
  • MySQL LIKE %string% 不够宽容。我还有什么可以用的吗?

    我有一位客户询问他们的搜索是否可以搜索公司名称 这些名称可以根据用户输入以多种格式进行搜索 例如数据库中存储的公司是 A J R Kelly Ltd 如果用户搜索 一个 J R Kelly 被发现 使用
  • PostgreSQL 在递归查询中找到所有可能的组合(排列)

    输入是一个长度为 n 的数组 我需要生成数组元素的所有可能组合 包括输入数组中元素较少的所有组合 IN j A B C OUT k A AB AC ABC ACB B BA BC BAC BCA 随着重复 所以AB BA 我尝试过这样的事情
  • 私人聊天系统MYSQL查询显示发送者/接收者的最后一条消息

    在这里我延伸一下我之前的问题 私人聊天系统MYSQL查询ORDERBY和GROUPBY https stackoverflow com questions 10929366 private chat system mysql query o
  • 使用条件 SQL 统计每月汇总记录

    我有一张桌子 我们就叫他们桌子吧SUMMARYDATA NIP NAME DEPARTMENT STATUSIN STATUSOUT TOTALLOSTTIME A1 ARIA BB 2020 01 21 08 06 23 2020 01
  • 如何在 Spring Data 中选择不同的结果

    我在使用简单的 Spring Data 查询或 Query 或 QueryDSL 在 Spring Data 中构建查询时遇到问题 如何选择三列 研究 国家 登录 不同的行 并且查询结果将是用户对象类型的列表 Table User Id S
  • 如何引用下一行的数据?

    我正在 PostgreSQL 9 2 中编写一个函数 对于股票价格和日期的表 我想计算每个条目较前一天的百分比变化 对于最早一天的数据 不会有前一天 因此该条目可以简单地为 Nil 我知道WITH声明可能不应该高于IF陈述 到目前为止 这就
  • 是否可以将新表和旧表从触发器传递到 MySQL 中的过程中?

    是否可以将新表和旧表从触发器传递到 MySQL 中的过程中 我怀疑不会 因为没有过程接受的表这样的数据类型 有什么可能的解决方法吗 理想情况下它看起来像这样 CREATE TRIGGER Product log AFTER UPDATE O
  • ASP SQL Server 连接

  • MySQL:如何获取每个分组的x个结果数[重复]

    这个问题在这里已经有答案了 可能的重复 mysql 在 GROUP BY 中使用 LIMIT 来获取每组 N 个结果 https stackoverflow com questions 2129693 mysql using limit w
  • java库维护数据库结构

    我的应用程序一直在开发 所以偶尔 当版本升级时 需要创建 更改 删除一些表 修改一些数据等 通常需要执行一些sql代码 是否有一个 Java 库可用于使我的数据库结构保持最新 通过分析类似 db structure version 信息并执
  • 分组和切换列和行

    我不知道这是否会被正式称为枢轴 但我想要的结果是这样的 Alex Charley Liza 213 345 1 23 111 5 42 52 2 323 5 23 1 324 5 我的输入数据采用这种形式 Apt Name
  • MySQL - 选择一行 - 然后相对于所选行的下一个和上一个

    我会尽力澄清这一点 我需要在不使用 id 的情况下选择特定行和该选定行的前一个相对行以及该选定行的下一个相对行 这可能吗 简而言之 上一篇和下一篇 我不能 也许我只是不知道如何 使用 id 的原因是因为它们不是按顺序排列的 正如您从这个相当

随机推荐