开发者

how do i combine and sum two results in sql?

开发者 https://www.devze.com 2022-12-21 08:22 出处:网络
i have one table, let\'s call it \'TBL\'. i have one column that have only 3 values available.(let\'s say \'AAA\', \'BBB\', \'CCC\')

i have one table, let's call it 'TBL'.

i have one column that have only 3 values available.(let's say 'AAA', 'BBB', 'CCC')

the values can return multiple times.

for example:

TBL
---

Column1
-------
AAA
AAA
BBB
CCC
BBB
CCC
BBB
CCC
AAA

i want to create a table result that looks like this:

TBL-RESULT
----------
AAA+BBB 60%
CCC     40%

i want to show AAA and BBB in one result and there precentage from all values 开发者_开发技巧in one line, and CCC in a second line as well.

the big problem is also that i need to do so in sql of ACCESS (2007).

can someone help me?

thank you, gady m


Assume table is called MyTable and column is MyColumn

    select IIF(MyColumn<>'CCC', 'AAA+BBB', 'CCC'), 
     100*count(MyColumn='CCC')/(select count(*) from MyTable) from MyTable
     group by MyColumn='CCC'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号