<bdo id='nKllT'></bdo><ul id='nKllT'></ul>
<tfoot id='nKllT'></tfoot>
  • <legend id='nKllT'><style id='nKllT'><dir id='nKllT'><q id='nKllT'></q></dir></style></legend>

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

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

        MySQL 计算多列上的不同值

        MySQL Counting Distinct Values on Multiple Columns(MySQL 计算多列上的不同值)

          <tfoot id='WZZDv'></tfoot>
          <legend id='WZZDv'><style id='WZZDv'><dir id='WZZDv'><q id='WZZDv'></q></dir></style></legend>

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

                  <tbody id='WZZDv'></tbody>
              • <i id='WZZDv'><tr id='WZZDv'><dt id='WZZDv'><q id='WZZDv'><span id='WZZDv'><b id='WZZDv'><form id='WZZDv'><ins id='WZZDv'></ins><ul id='WZZDv'></ul><sub id='WZZDv'></sub></form><legend id='WZZDv'></legend><bdo id='WZZDv'><pre id='WZZDv'><center id='WZZDv'></center></pre></bdo></b><th id='WZZDv'></th></span></q></dt></tr></i><div id='WZZDv'><tfoot id='WZZDv'></tfoot><dl id='WZZDv'><fieldset id='WZZDv'></fieldset></dl></div>
                  <bdo id='WZZDv'></bdo><ul id='WZZDv'></ul>
                  本文介绍了MySQL 计算多列上的不同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我编写了一个脚本,每次用户登录我们域中的计算机时都会运行该脚本.该脚本会记录用户以及他们登录的计算机.任意数量的用户可以登录任意数量的计算机.

                  I wrote a script that runs each time a user logs into a computer in our domain. This script makes a record of the user as well as the computer they logged into. Any number of users can log into any number of computers.

                  我刚刚从一位已不在的顾问那里继承了这个 IT 环境,我正在编写这个小查询,因此当我接到用户的电话时,我可以通过该用户的名称进行搜索并合理地预测他们是哪台计算机按他们登录任何给定计算机的次数使用.

                  I just inherited this IT environment from a consultant who is no longer around, and I'm writing this little query so when I get a call from a user, I can search by that user's name and reasonably predict which computer they are using by the number of times they've logged into any given computer.

                  以下是登录"表中的数据示例:

                  Here's a sample of the data in the 'login' table:

                      COMPUTER        USER
                      ncofp02         lee
                      ncofp02         lee
                      ncofp02         andy
                      ncodc01         andy
                      ncodc01         andy
                      ncodc01         lee
                  

                  让我头疼的是在多列中计算不同值的逻辑.我希望看到这样的结果:

                  What I'm banging my head on is the logic to count distinct values across multiple columns. I'd like to see a result like this:

                      COMPUTER       USER   COUNT
                      ncofp02        lee    (2)
                      ncofp02        andy   (1)
                      ncodc01        lee    (1)
                      ncodc01        andy   (2)
                  

                  有没有办法用 mysql 中的单个查询来完成这个,或者我应该开始循环一些 php?(嘘!)

                  Is there a way to accomplish this with a single query within mysql, or should I start looping some php? (booooo!)

                  推荐答案

                  只需在 GROUP BY 子句中列出多个列.

                  Just list multiple columns in the GROUP BY clause.

                  SELECT computer, user, count(*) AS count
                  FROM login
                  GROUP BY computer, user
                  

                  这篇关于MySQL 计算多列上的不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                • <tfoot id='yvJZQ'></tfoot>

                  <legend id='yvJZQ'><style id='yvJZQ'><dir id='yvJZQ'><q id='yvJZQ'></q></dir></style></legend>
                    <tbody id='yvJZQ'></tbody>

                  1. <small id='yvJZQ'></small><noframes id='yvJZQ'>

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