计算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
最满意答案
它与最后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 ...
-
Laravel4中的多租户(Multi-tenant in Laravel4)[2023-01-14]
实现此目的的最佳方法是在应用于路由组的前置过滤器中。 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 ...
-
Nginx别名与laravel4(Nginx alias with laravel4)[2022-08-19]
简而言之,进行以下编辑。 下面解释原因。 更换 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属性是可见的,因为它在运行时受到保护和修改。 最后, ...
-
无法使用Laravel4发送邮件(Can't send mail with Laravel4)[2022-09-21]
一些东西 对于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 ...