我需要解决我的问题。
我有2个表,assetdetail和assetcondition。这是表格的结构。
assetdetail
-----------------------------------------------------------
| sequenceindex | assetcode | assetname | acquisitionyear |
-----------------------------------------------------------
| 1 | 110 | Car | 2012-06-30 |
| 2 | 111 | Bus | 2013-02-12 |
assetcondition
--------------------------------------------------------------------------
|sequenceindex | indexassetdetail | fiscalyear | assetamount | assetprice |
---------------------------------------------------------------------------
| 1 | 1 | 2012 | 1 | 20000000 |
| 2 | 1 | 2013 | 1 | 15000000 |
| 3 | 2 | 2013 | 1 | 25000000 |
我希望结果是这样的:
------------------------
assetname | assetprice |
------------------------
Car | 20000000 |
Bus | 25000000 |
注意:使用“SELECT WHERE fiscalyear =
”
答案 0 :(得分:0)
我从逻辑的角度来理解您的查询。顺便说一句,你必须使用的操作员是JOIN的操作员。 接下来的SQL,我不知道它是不是你想要的。
Select assetname, assetprice
From assetdetail as ad join assetcondition as ac on (as.sequenceindex = ac.sequenceindex)
Where fiscalyear = '2013'
答案 1 :(得分:0)
不太确定这是否是您正在寻找的内容,但我想您想要的是JOIN
:
SELECT
assetdetail.assetname, assetcondition.assetprice
FROM
assetdetail
JOIN
assetcondition
ON
assetdetail.sequenceindex = assetcondition.sequenceindex
WHERE
YEAR(acquisitionyear) = '2013'
答案 2 :(得分:0)
如果没有解释你的表如何链接,我们只能猜测。这是我提出的查询。
select assetdetail.assetname,
sum( assetcondition.assetprice )
from assetdetail
inner join assetcondition
on assetcondition.indexassetdetail = assetdetail.sequenceindex
where assetcondition.fiscalyear = 2013
group by assetdetail.assetname;