小编Sag*_*ara的帖子

如何高效地编写SQL条件?

我有以下非常大的(~10e8记录)表(table):

+--------------------------------+
|      id      order       value |
+--------------------------------+
|      PK       int         int  |
|       1        1           1   |
|       2        2           5   |
|       3        2               |
|       4        2           0   |
+--------------------------------+

如您所见,value列只能包含非负整数或null.现在,我需要编写一个返回没有a的订单的查询value > 0(即order = 2不保存条件,因为有记录value = 5).

反向查询很简单:

SELECT order
FROM table
WHERE value > 0
Run Code Online (Sandbox Code Playgroud)

查询的性能对我来说是令人满意的.

但我们不能写

SELECT order
FROM table
WHERE value = 0
Run Code Online (Sandbox Code Playgroud)

因为有可能有一个具有相同订单的记录,但有value > 0.我能找到写这个查询的唯一方法是:

SELECT order
FROM table
GROUP BY …
Run Code Online (Sandbox Code Playgroud)

sql postgresql

3
推荐指数
1
解决办法
57
查看次数

Angular Material Date Picker 选择的默认日期

这对我的日期选择器有帮助

现在,date-picker我希望默认选择今天的日期。

谁能帮我设置默认日期?

谢谢你。

datepicker angularjs angular-material

3
推荐指数
1
解决办法
1万
查看次数

Laravel 5.1使用限制在()方法中的雄辩

雄辩

$staffGroup = StaffGroup::where('id', $id)
            ->with('staffGroupRight')
            ->first();
Run Code Online (Sandbox Code Playgroud)

StaffGroup Model:

public function staffGroupRight() {
    return $this->hasMany('Modules\Staff\Http\Models\StaffGroupRight');
}
Run Code Online (Sandbox Code Playgroud)

我所做的是,

public function staffGroupRight() {
    return $this->hasMany('Modules\Staff\Http\Models\StaffGroupRight')->take(5);
}
Run Code Online (Sandbox Code Playgroud)

但它总共给出了5行,staff_group但我希望它能limit用于一个staff_group

例如

有10 staff_group则给出了5条的staffgrouprights为10 staff_group,但我想它5单staff_group

这里staffGroupRight返回data适当idstaff group.

但我想limit在那个with()方法数据中设置.

是否有可能limitwith()方法中设置......?

limit laravel eloquent laravel-5.1

3
推荐指数
1
解决办法
4319
查看次数

'ReflectionException'类翻译器不存在

我正在尝试使用本地化,如下

$types = trans('constants.type');
Run Code Online (Sandbox Code Playgroud)

我创建constants.php了如下文件(在config目录中),这是它的语言文件,

/resources
    /lang
        /en
            constants.php
        /es
            constants.php
Run Code Online (Sandbox Code Playgroud)

constants.php

return ['type' => 'Type'];
Run Code Online (Sandbox Code Playgroud)

它在同一格式的其他文件中翻译的方式相同,但这件事给了我以下错误

注意:我在config目录的文件中使用了这个,

(1/1)ReflectionException类转换器不存在

在ReflectionClass中的Container.php(第729行) - 在Container.php(第729行)中的Container.php(第729行)中的Container-> build('translator')在Container.php(第608行)中的Container-> resolve( Container.php中的'translator')(第575行)在Container-> make('translator')

问题:

trans()方法不在constants.php我在config目录中创建的文件中工作如下,

/ config constants.php

localization laravel laravel-5

3
推荐指数
1
解决办法
4739
查看次数

laravel:更新行时如何将列的当前值乘以某个值?

问题:

我想更新 mysql 表的两列,

column1减去某个值并column2乘以某个值,

我从这里做了这样的减量

尝试过:

$stock_obj->decrement('quantity_on_hand', $product_data["quantity"], array(
    'total_quantity_on_hand' => 'quantity_on_hand' * some_other_value
));
Run Code Online (Sandbox Code Playgroud)

这里减法有效,但我该如何做乘法呢?

我在 CI(CodeIgniter) 中有这个解决方案,但不知道如何在 laravel 中做到这一点,任何帮助将不胜感激......

CI(代码点火器)方式:

$this->db->set("quantity_on_hand", "quantity_on_hand-" . ($product_data["quantity"] ? $product_data["quantity"] : 0), FALSE);
$this->db->set("total_quantity_on_hand", "quantity_on_hand*" . ($product_data['product_packing_value'] ? $product_data['product_packing_value'] : 1), FALSE);
$this->db->where("id", $warehouse_transfer_product_data['stock_id'])->update("stock");
Run Code Online (Sandbox Code Playgroud)

php mysql laravel eloquent laravel-5

1
推荐指数
1
解决办法
3772
查看次数

JavaScript中的Sin和cos

我正在尝试用JavaScript构建计算器.它除了罪和cos之外都有效,它们给出了错误和意想不到的结果.

Sin和Cos给出了错误的结果

罪(180)= 0

在代码sin(180)= - 0.8011526357338304

在此输入图像描述

我的代码如下所示,

JavaScript的:

function d(val){
    if(val=="sin"){
        var x=document.getElementById("d").value;
        document.getElementById("d").value=Math.sin(x);
    }
    if(val=="cos"){
        var x=document.getElementById("d").value;
        document.getElementById("d").value=Math.cos(x);
    }
    if(val=="envers"){
        var x=document.getElementById("d").value;
        document.getElementById("d").value=eval(1/x);
    }
    if(val=="sqrt"){
        var x=document.getElementById("d").value;
        document.getElementById("d").value=Math.sqrt(x);
    }
}

function c(val){
    document.getElementById("d").value=val;
}

function v(val){
    document.getElementById("d").value+=val;
}

function e(){ 
    try { 
      c(eval(document.getElementById("d").value)) 
    } 
    catch(e){
        c('Error') 
    } 
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="display">
    <p>
        <input type="text" readonly size="14" id="d">
        <input type="button" class="button black" value="C" onclick='c("")'>  
    </p>
</div>
<div class="keys">
    <p>
        <input type="button" class="button black" value="1" onclick='v("1")'>
        <input type="button" …
Run Code Online (Sandbox Code Playgroud)

javascript

-1
推荐指数
1
解决办法
2454
查看次数