Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择有条件引用另一行的行sqlite_Sql_Sqlite - Fatal编程技术网

选择有条件引用另一行的行sqlite

选择有条件引用另一行的行sqlite,sql,sqlite,Sql,Sqlite,我有一个表,其中我想根据另一行值有条件地计算一些行值 这张桌子看起来像这样 LevelID StepID Amt Type BItem PItem ------------------------------------------------- 6 3 18000 Fixed BS 6 3 10 Percent BS UA 6 3 10

我有一个表,其中我想根据另一行值有条件地计算一些行值

这张桌子看起来像这样

LevelID StepID  Amt     Type    BItem       PItem
-------------------------------------------------
6       3       18000   Fixed               BS
6       3       10      Percent BS          UA
6       3       10      Percent BS          TA
6       3       3.5     Percent BS          Tx
7       3       24000   Fixed               BS
7       3       10      Percent BS          UA
7       3       10      Percent BS          TA
7       3       3.5     Percent BS          Tx
目的是计算类型为='Percent'的行的金额值,其中Bitem=PItem,而LevelID和StepID对于Bitem和PItem都是相同的

因此,示例输出将是

LevelID StepID  Amt     Type    BItem       PItem   Total
----------------------------------------------------------
6       3       18000   Fixed               BS      18,000
6       3       10      Percent BS          UA      1,800
6       3       10      Percent BS          TA      1,800
6       3       3.5     Percent BS          Tx      630
7       3       24000   Fixed               BS      24,000
7       3       10      Percent BS          UA      2,400
7       3       10      Percent BS          TA      2,400
7       3       3.5     Percent BS          Tx      840
我一直在尝试不同的SQL语句,但尚未获得任何合理的输出

要查找值,请使用:


非常感谢,我写了一个类似的相关子查询,但确实得到了它并给出了结果
SELECT *,
       CASE Type
       WHEN 'Fixed' THEN Amt
       ELSE (SELECT B.Amt * ATable.Amt / 100
             FROM ATable AS B
             WHERE B.Type = 'Fixed'
               AND B.LevelID = ATable.LevelID
               AND B.StepID  = ATable.StepID
               AND B.PItem   = ATable.BItem)
       END AS Total
FROM ATable;