首页 \ 问答 \ 计算MySql中的百分比(Calculate Percentage in MySql)

计算MySql中的百分比(Calculate Percentage in MySql)

我想根据我桌子的特定产品的数量来计算百分比。我想根据下表的计算添加百分比列。表格列是:

Item_Category : It gives the item name
Item_Amount : It gives the sum of the particular item

我使用的查询是:

select Item_Category,
      (SUM(Item_Amount)/100000) as Total,
      quarter(Invoice_date) as Quarter,
      year(Invoice_date) as Year 
from `cmpsldata` 
where Site='BDD1' 
      and Item_code LIKE 'FG%' 
      and Invoice_type='Excise'    
group by Year,Item_Category,Quarter 
order by Total desc

Table : 
| Item_Category | Total | Quarter | Year |
| Product A     | 78.65 | 1       | 2015 |
| Product B     | 65.54 | 1       | 2015 |
| Product C     | 45.78 | 1       | 2015 |

这是当前表格,我现在需要再添加一列,这样我就可以得到产品A,B,C的百分比计算(单独)。


I want to calculate percentage on basis on amount for a particular product for my table.I want to add percentage column on basis of the calculation according to the following table.The table column are :

Item_Category : It gives the item name
Item_Amount : It gives the sum of the particular item

The query which i have used is :

select Item_Category,
      (SUM(Item_Amount)/100000) as Total,
      quarter(Invoice_date) as Quarter,
      year(Invoice_date) as Year 
from `cmpsldata` 
where Site='BDD1' 
      and Item_code LIKE 'FG%' 
      and Invoice_type='Excise'    
group by Year,Item_Category,Quarter 
order by Total desc

Table : 
| Item_Category | Total | Quarter | Year |
| Product A     | 78.65 | 1       | 2015 |
| Product B     | 65.54 | 1       | 2015 |
| Product C     | 45.78 | 1       | 2015 |

This is the current table now i need to add 1 more column which gives me percentage calculation of the Product A, B , C(individually).


原文:https://stackoverflow.com/questions/32322901
更新时间:2022-07-08 14:07

最满意答案

它与最后4项不匹配,因为项目在控制器之前不包含\。 你的正则表达式要求他们拥有它,因此不符合它。 答案是使用?使初始斜杠可选? (= 0或1次出现),如下:

(.*)\\?(.*)Controller@(get|post|put|delete|patch)(.*)

在旁注中,您确定控制器没有具体名称吗? 即。 一个名为“Controller”的控制器也会匹配你的正则表达式。 要禁止(并且只允许[某些]控制器),您可以将第二个。*更改为。+(因此从0或更多匹配更改为1个或多个匹配)。 像这样:

(.*)\\?(.+)Controller@(get|post|put|delete|patch)(.*)

和你的方法一样(get | post | etc.):

(.*)\\?(.+)Controller@(get|post|put|delete|patch)(.+)

It isn't matching the last 4 items because the items do not contain a \ before the controller. Your regexp requires them to have it, and as such does not match it. The answer is to make the initial slash optional by using a ? (=0 or 1 occurrence), like so:

(.*)\\?(.*)Controller@(get|post|put|delete|patch)(.*)

On a sidenote, are you sure that a Controller have no specific name? ie. a controller just called "Controller" will match your regexp as well. To disallow that (and only allow [something]Controller) you can change the 2nd .* to .+ (so from 0 or more matches to 1 or more matches). Like so:

(.*)\\?(.+)Controller@(get|post|put|delete|patch)(.*)

And the same thing for your method (get|post|etc.):

(.*)\\?(.+)Controller@(get|post|put|delete|patch)(.+)

相关问答

更多
  • 您可以使用完全相同的方式命名到控制器的路径。 将控制器和方法名称作为“uses”关键字下的数组中的第二项: Route::get('user/profile', array("as" => "profile", "uses" => "UserController@profile")); You can name your route to controller exactly the same way. Put controller and method name as second item in ar ...
  • 您将需要重新加载整个页面,因为在解析刀片文件期间呈现字符串。 Ajax请求会为您在会话中保存已使用的区域设置,但不会再次呈现您的页面。 如果您想在不重新加载的情况下更改页面内容,则必须使用JavaScript: 使用Ajax发送'locale change'请求 返回要更改的字符串(例如,作为JSON对象) 使用JS将所需的DOM元素更改为接收的语言环境 这可以(取决于你想要改变的元素的数量)安静很多工作。 我仍然建议重新加载页面,我认为它不会改变您网页的可用性。 You will need to relo ...
  • 实现此目的的最佳方法是在应用于路由组的前置过滤器中。 Route::group(['domain' => '{account}.myapp.com', 'before' => 'database.setup'], function() { // Your routes... } 在过滤器获取$route参数和给它的$request参数之前,我们可以使用$request来获取主机。 Route::filter('database.setup', function($route, $request) ...
  • Laravel 4在内核中没有LDAP认证。 所以这是一种快速和肮脏的方式将它添加到您的应用程序。 它使用内部LDAP PHP函数,因此您需要安装php5-ldap软件包: 为你的app / conf / auth.php配置: 'ldap_tree' => 'OU=anything,DC=domain,DC=com', 'ldap_server' => 'your.ldap.server.com', 这是您的控制器要使用的LDAP类: class LDAP { public static ...
  • 简而言之,进行以下编辑。 下面解释原因。 更换 try_files $uri $uri/ /index.php?$query_string; 同 try_files $uri $uri/ /lara/index.php?$query_string; 用这个替换最后一个location指令 location ~ /lara/(.*)$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fa ...
  • 它与最后4项不匹配,因为项目在控制器之前不包含\。 你的正则表达式要求他们拥有它,因此不符合它。 答案是使用?使初始斜杠可选? (= 0或1次出现),如下: (.*)\\?(.*)Controller@(get|post|put|delete|patch)(.*) 在旁注中,您确定控制器没有具体名称吗? 即。 一个名为“Controller”的控制器也会匹配你的正则表达式。 要禁止(并且只允许[某些]控制器),您可以将第二个。*更改为。+(因此从0或更多匹配更改为1个或多个匹配)。 像这样: (.*)\\ ...
  • 你的dbeloquent类正在后台扩展Model类。 Eloquent别名指向app / config / app.php文件中的Model类 'Eloquent'=>'照亮\数据库\ Eloquent \ Model' protected $ table属性是从抽象的Model类扩展而来的,它不是静态的,所以你不能重新声明它(静态或静态)。你可以从基本模型访问属性的方法是: __get($key) method 但问题是在哪个执行点上你的$ table属性是可见的,因为它在运行时受到保护和修改。 最后, ...
  • 一些东西 对于gmail ssl,端口应为'465' 'port' => 465, 并且你'假装'设置为真 - 所以不会发送电子邮件! 'pretend' => false 如果你真的不想发送电子邮件,请保留pretend => true然后查看app/storage/logs文件夹中的'假'电子邮件 A few things Port should be '465' for gmail ssl 'port' => 465, and you have 'pretend' set to true - s ...
  • 你可以使用preg_match_all完成这项工作 $string="a,b,c,(d,e,f),g,'h, i j.',k"; preg_match_all('~\'[^\']++\'|\([^)]++\)|[^,]++~', $string,$result); print_r($result[0]); 说明: 诀窍是在之前匹配括号, ~ Pattern delimiter ' [^'] All charaters but not a single quote ++ ...
  • 检查从浏览器直接显示图像时出现的错误。(我的意思是在浏览器中输入图像的完整URL)。 确保laravel生成的URL和实际图像URL相同。 如果您可以直接从浏览器显示图像。 所有图像都应该在公共文件夹中,并且通常不应该在基础中有.htacces文件。(我的意思是公共下面的文件夹) 确保公共文件夹中的.htaccess ile是这样的, Options -MultiViews RewriteEngine On ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)