Sql Server 2008 Cross Tab Query

后端 未结 2 833
滥情空心
滥情空心 2020-12-06 14:02

I usually can figure out any sql queries I need for my applications, but I have recently been stumped by a Cross Tab query I need to create and was wondering if you could he

2条回答
  •  甜味超标
    2020-12-06 14:37

    I think your missing a table that make a reference between your site and equipment

    Something like that :

    EquipmentSite(SiteID, EquipID)
    

    Because now it's impossible to tell wich site as wich equipment

    EDIT :

    Since the siteID is also in equipment I would propose another table, a little refactor of you database (because I really don't know how to do this)

    If you get a lot of data it would be a mess to fetch the data and calculate every thing every time you want to access those data.

    So I propose this table

    siteCatCount(CatID, siteID, cnt)
    

    So when you modify you data (add or remove equipment) you would go update this table, it would be much clearer and you wont have to calculate the count of every equipment each time

提交回复
热议问题