sql server - SQL Query for getting the count and Rows with multiple record -
i'm trying figure out sql query sql server this:
table:
id appointmentid typeid ------------------------------ 1 1992 1 2 1992 1 3 1992 2 4 1993 1 ... desired result:
appointmentid typecount typeid --------------------------------- 1992 2 1 i looking appointmentid of typeid = 1 got count of more 1.
thanks,
the table have:
create table appointments ( id int, appointmentid int, typeid int ); some data:
insert appointments values (1, 1992, 1); insert appointments values (2, 1992, 1); insert appointments values (3, 1992, 2); insert appointments values (4, 1993, 1); query:
select appointmentid, count(*) typecount, typeid appointments typeid = 1 group appointmentid, typeid having count(*) > 1;
Comments
Post a Comment