与sql中派生列的区别

时间:2015-12-14 09:52:03

标签: mysql

我有一个查询。我将两个列值添加到一个派生列,然后我想从派生列和已存在的列中获取差异。 但是我得到了一些未知的列错误

<div class="hexagon-wrapper">
  <img class="hexagon" src="http://lorempixel.com/150/150/people/1" />
</div>

任何人都知道可能出现的问题?

1 个答案:

答案 0 :(得分:0)

如果您要查找特定amountpending

feest_id

然后

SELECT  
    `st_id` ,  
    `fee` , 
    SUM(  `total` ) AS total, 
    SUM(  `books` ) AS book,
    SUM(  `uniform` ) AS uniform,
    SUM(  `total` + `books` + `uniform` ) AS amount,
    SUM(  `total` + `books` + `uniform` - `paid` ) AS pending
FROM  `fee_tbl` 
WHERE  `st_id` IN ( 40, 504, 533, 640, 817, 944 ) 
GROUP BY  `fee` ,  `st_id`

SELECT  
    `st_id` ,  
    `fee` , 
    SUM(  `total` ) AS total, 
    SUM(  `books` ) AS book,
    SUM(  `uniform` ) AS uniform,
    SUM(  `total` ) + SUM(  `books` ) + SUM(  `uniform` ) AS amount,
    SUM(  `total` ) + SUM(  `books` ) + SUM(  `uniform` ) - SUM(`paid` ) AS pending
FROM  `fee_tbl` 
WHERE  `st_id` IN ( 40, 504, 533, 640, 817, 944 ) 
GROUP BY  `fee` ,  `st_id`