• <small id='DGZwJ'></small><noframes id='DGZwJ'>

      1. <tfoot id='DGZwJ'></tfoot>
        <legend id='DGZwJ'><style id='DGZwJ'><dir id='DGZwJ'><q id='DGZwJ'></q></dir></style></legend>

          <bdo id='DGZwJ'></bdo><ul id='DGZwJ'></ul>
      2. <i id='DGZwJ'><tr id='DGZwJ'><dt id='DGZwJ'><q id='DGZwJ'><span id='DGZwJ'><b id='DGZwJ'><form id='DGZwJ'><ins id='DGZwJ'></ins><ul id='DGZwJ'></ul><sub id='DGZwJ'></sub></form><legend id='DGZwJ'></legend><bdo id='DGZwJ'><pre id='DGZwJ'><center id='DGZwJ'></center></pre></bdo></b><th id='DGZwJ'></th></span></q></dt></tr></i><div id='DGZwJ'><tfoot id='DGZwJ'></tfoot><dl id='DGZwJ'><fieldset id='DGZwJ'></fieldset></dl></div>

        坚持构建 MySQL 查询

        Stuck in building MySQL query(坚持构建 MySQL 查询)

        <small id='UKVdL'></small><noframes id='UKVdL'>

        <i id='UKVdL'><tr id='UKVdL'><dt id='UKVdL'><q id='UKVdL'><span id='UKVdL'><b id='UKVdL'><form id='UKVdL'><ins id='UKVdL'></ins><ul id='UKVdL'></ul><sub id='UKVdL'></sub></form><legend id='UKVdL'></legend><bdo id='UKVdL'><pre id='UKVdL'><center id='UKVdL'></center></pre></bdo></b><th id='UKVdL'></th></span></q></dt></tr></i><div id='UKVdL'><tfoot id='UKVdL'></tfoot><dl id='UKVdL'><fieldset id='UKVdL'></fieldset></dl></div>
          <tbody id='UKVdL'></tbody>

          • <bdo id='UKVdL'></bdo><ul id='UKVdL'></ul>

            1. <tfoot id='UKVdL'></tfoot><legend id='UKVdL'><style id='UKVdL'><dir id='UKVdL'><q id='UKVdL'></q></dir></style></legend>
                1. 本文介绍了坚持构建 MySQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  给出一个表格的例子:

                  id |item_id |用户 ID |竞标价格----------------------------------

                  任务是为提供的集合中的每个 item_id 选择具有 minimum bid_pricerows.p>

                  例如:item_id = [1, 2, 3] - 所以我需要选择最多三 (3) 行,且具有最低 bid_price.p>

                  数据示例:

                  id |item_id |用户 ID |竞标价格----------------------------------1 |1 |11 |12 |1 |12 |23 |1 |13 |34 |1 |14 |15 |1 |15 |46 |2 |16 |27 |2 |17 |18 |3 |18 |29 |3 |19 |310 |3 |18 |2

                  预期结果:

                  id |item_id |用户 ID |竞标价格----------------------------------1 |1 |11 |17 |2 |17 |18 |3 |18 |2

                  实际上,我使用的是 Symfony/Docine DQL,但使用简单的 SQL 示例就足够了.

                  解决方案

                  对于行中的所有列,您可以在 subselect 上使用内部联接以获得最低出价

                  选择 m.id, m.item_id, m.user_id, m.bid_price从 my_table m内部联接 (选择 item_id, min(id) min_id, min(bid_price) min_price来自 my_table其中 item_id IN (1,2,3)按 item_id 分组) t 上 t.item_id = m.item_id和 t.min_price=m.bid_price和 t.min_id = m.id

                  或者 .. 如果你有一些浮点数据类型,你可以使用 acst 来表示无符号

                   select m.id, m.item_id, m.user_id, cast(m.bid_price as UNSIGNED)从 my_table m内部联接 (选择 item_id, min(id) min_id, min(bid_price) min_price来自 my_table其中 item_id IN (1,2,3)按 item_id 分组) t 上 t.item_id = m.item_id和 t.min_price=m.bid_price和 t.min_id = m.id

                  Given an example of table:

                  id | item_id | user_id | bid_price
                  ----------------------------------
                  

                  The task is to select rows with minimum bid_price for each item_id in the provided set.

                  For example: item_id = [1, 2, 3] - so I need to select up to three (3) rows, having a minimum bid_price.

                  Example of data:

                  id | item_id | user_id | bid_price
                  ----------------------------------
                   1 |    1    |   11    |     1
                   2 |    1    |   12    |     2
                   3 |    1    |   13    |     3
                   4 |    1    |   14    |     1
                   5 |    1    |   15    |     4
                   6 |    2    |   16    |     2
                   7 |    2    |   17    |     1
                   8 |    3    |   18    |     2
                   9 |    3    |   19    |     3
                  10 |    3    |   18    |     2
                  

                  Expected result:

                  id | item_id | user_id | bid_price
                  ----------------------------------
                   1 |    1    |   11    |     1
                   7 |    2    |   17    |     1
                   8 |    3    |   18    |     2
                  

                  Actually, I'm using Symfony/Docine DQL, but it will be enough with a plain SQL example.

                  解决方案

                  For the all the columns in the rows you could use a inner join on subselect for min bid price

                  select m.id, m.item_id, m.user_id, m.bid_price
                  from my_table m 
                  inner join ( 
                  select item_id, min(id) min_id,  min(bid_price) min_price
                  from my_table 
                  where   item_id IN (1,2,3)
                  group by item_id 
                  ) t on t.item_id = m.item_id 
                     and t.min_price= m.bid_price
                     and t.min_id = m.id
                  

                  or .. if you have some float data type you could use a acst for unsigned

                    select m.id, m.item_id, m.user_id, cast(m.bid_price as UNSIGNED) 
                    from my_table m 
                    inner join ( 
                    select item_id, min(id) min_id,  min(bid_price) min_price
                    from my_table 
                    where   item_id IN (1,2,3)
                    group by item_id 
                    ) t on t.item_id = m.item_id 
                       and t.min_price= m.bid_price
                       and t.min_id = m.id 
                  

                  这篇关于坚持构建 MySQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tfoot id='bP6qj'></tfoot>
                    <i id='bP6qj'><tr id='bP6qj'><dt id='bP6qj'><q id='bP6qj'><span id='bP6qj'><b id='bP6qj'><form id='bP6qj'><ins id='bP6qj'></ins><ul id='bP6qj'></ul><sub id='bP6qj'></sub></form><legend id='bP6qj'></legend><bdo id='bP6qj'><pre id='bP6qj'><center id='bP6qj'></center></pre></bdo></b><th id='bP6qj'></th></span></q></dt></tr></i><div id='bP6qj'><tfoot id='bP6qj'></tfoot><dl id='bP6qj'><fieldset id='bP6qj'></fieldset></dl></div>
                      <tbody id='bP6qj'></tbody>
                    • <legend id='bP6qj'><style id='bP6qj'><dir id='bP6qj'><q id='bP6qj'></q></dir></style></legend>
                        • <bdo id='bP6qj'></bdo><ul id='bP6qj'></ul>

                          <small id='bP6qj'></small><noframes id='bP6qj'>