数据挖掘预测中的存储过程

时间:2016-12-18 21:11:47

标签: mysql

我正在尝试编写一个存储过程来显示(fid,name,tel,income,balance,loan_amount,child_count)来自两个表 家庭(FID,姓名,电话,收入,good_credit,平衡) 儿童(CID,姓名,年龄,FID)。该功能应该能够根据以下标准预测谁可以成为潜在客户: 良好的信用,余额> = 3000,child_count:18至22岁之间的子女总数,收入:40000和loan_amount =收入* 0.3 * child_count

      Family table
      fid  name  tel   income  good_credit balance
      1    aaa1  111   15000    1           1000
      2    aaa2  211   25000    0           10000
      3    aaa3  311   80000    0           1000
      4    aaa4  411   40000    1           7000

      Children table
      cid   name    age   fid
      1     bbb1     14    3
      2     bbb2     14    15
      3     bbb3     19    16
      4     bbb4     18    9

我的代码看起来像这样,但我收到错误“子查询返回多行”

      delimiter $$
      CREATE PROCEDURE procc()
      BEGIN
      declare loan_amount int (200);
      declare child_count int (200);
      set child_count = (select count(age) from Children,Family where age             between 18 and 22 );
      set loan_amount = (select income from Children CV,Family DV where   DV.FID = CV.FID);
      if (child_count is not null) then select cf.FID as FID, cf.Name as         Name, cf.TEL as TEL, cf.income as income, cf.balance as balance, child_count, loan_amount * 0.3 * child_count from Family  cf,Children cc
     where cf.FID = cc.FID and good_credit = 1 and income >= 40000 and       balance = 3000;
     end if;
     end$$
     delimiter ; 

0 个答案:

没有答案