从表中选择最大计数并更新另一列

时间:2014-09-30 09:41:44

标签: sql sql-server

enter image description here

enter image description here

我需要从col1_class列中查找Count的最大值,并更新table2列' lbl1'有价值的 我尝试了这段代码,但是我收到了错误:

update testClassLable
set lbl1 = (
    select max(maxVal)
    from (
        select count (col1_class) as maxVal
        from tbl_test_all
        group by col1_class
    )x
)
你可以帮忙吗?

*更新*

我现在编辑了上面的代码及其工作,但它返回:

0行受影响!

1 个答案:

答案 0 :(得分:1)

试试这个

update testClassLable
set lbl1 = (
    select max(countVal)
    from (
        select count(col1_class) as countVal
        from tbl_test_all
        group by col1_class
    ) x
)