Select 特定年份的数据

Select data from specific year

我需要解决我的问题。

我有 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 =

我没有从逻辑的角度理解你的问题。顺便说一句,您必须使用的运算符是 JOIN 的运算符。 后面的SQL,不知道是不是你想要的。

    Select assetname, assetprice
From assetdetail as ad join assetcondition as ac on (as.sequenceindex = ac.sequenceindex)
Where fiscalyear = '2013'

不太确定这是否是您要找的东西,但我想您想要的是 JOIN:

SELECT
    assetdetail.assetname, assetcondition.assetprice
FROM
    assetdetail
JOIN
    assetcondition
ON
    assetdetail.sequenceindex = assetcondition.sequenceindex
WHERE
    YEAR(acquisitionyear) = '2013'

如果不解释您的表格是如何链接的,那么只能猜测。这是我提出的查询。

select assetdetail.assetname,
   sum( assetcondition.assetprice )

 from assetdetail
inner join assetcondition
   on assetcondition.indexassetdetail = assetdetail.sequenceindex

where assetcondition.fiscalyear = 2013
group by assetdetail.assetname;