doushen2154 2016-02-28 09:55
浏览 40

列取决于其他列

I have created a mysql table name 'members' where payment and ewallet are two columns... I want to make ewallet column such that it will automatically update when payment will update.. the rule will be ewallet=0.75*payment. How it is possible?

there is another column 'enroller_id' through which i am calculation the left count and the right count downline with the php function

function getTotalLeg($node,$leg){
$sql="select enrolled_id from members where enroller_id='$node' and tside='$leg' and active='1'";

$res=mysql_query($sql);

global $total;

$total=$total+mysql_num_rows($res);
$row=mysql_fetch_array($res);

 if($row['enrolled_id']!=''){
   getTotalLeg ($row['enrolled_id'],0);
   getTotalLeg ($row['enrolled_id'],1);
  }

return $total;
}

Is it possible to count it in the database? Please help me in detail way. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanfengtuo6012 2016-02-28 10:03
    关注

    You could use generated columns (MySQL 5.7.6+):

    Values of a generated column are computed from an expression included in the column definition.

    Generated column definitions have this syntax:

    col_name data_type [GENERATED ALWAYS] AS (expression) [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment] [[NOT] NULL] [[PRIMARY] KEY]

    CREATE TABLE members(
       ...,
       ewallet DECIMAL(14,4) AS (0.75 * payment)
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数