简体   繁体   中英

Find count of rows with same values SQL

I need to find count of rows with the same value and grouped by this value.

I dont have known value by which i can compare the rows, like this:

SELECT @2 = F.Batch,COUNT(*) count FROM table1 WHERE Row_value = 'qwerty' GROUP BY Raw_Value

I have table like this

???1    Some Description

???2    Some Description

???1    Some Description

???2    Some Description

???1    Some Description

Where in output i want to see:

???1 3

???2 2

Please, help!

I'm not entirely sure what your table structure is and the query you provided doesn't really map to the sample data but you really just need a simple count/group by syntax.

If you update your question to be more precise maybe I can update the answer to match your table structure and requirements better.

Provided you have a table structure like this:

CREATE TABLE Table1
    (`field 1` int, `field 2` varchar(16))
;

INSERT INTO Table1
    (`field 1`, `field 2`)
VALUES
    (1, 'Some Description'),
    (2, 'Some Description'),
    (1, 'Some Description'),
    (2, 'Some Description'),
    (1, 'Some Description')
;

You can get your expected output using this query:

select count(*) ,`field 1` from Table1 group by `field 1`

See this sqlfiddle for yourself

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM