0
テーブルのすべてのローを、where句で同じ値を持つローのカウントで更新したいとします。mysql update。 count、rows whereカラムがnullで、カラムが同じ
SQL私の現在のクエリは、この
UPDATE database.TableName AS A
SET refCount = (SELECT Count(*)
FROM database.TableName AS B
WHERE A.file1 = B.file1 AND A.file2 is null)
テーブル名のように見えます
//This gives me the rows I want to update
SELECT file1 FROM database.TableName where file2 is null
//From there I want to count all the rows that are the same
SELECT Count(*) FROM database.TableName where file1 = resulted value
//And then I want to update the row
|ID | file1 | file2 | refCount |
| 1 | file.txt | | 1 |
| 2 | file.txt | | 1 |
| 3 | | file2.txt | 1 |
| 4 | file3.txt | | 1 |
テーブル名(期待される成果)
|ID | file1 | file2 | refCount |
| 1 | file.txt | | 2 |
| 2 | file.txt | | 2 |
| 3 | | file2.txt | 1 |
| 4 | file3.txt | | 1 |