postgres row to column I have this pretty straightforward SQL query

SELECT count(date_mdy) AS unique_date_count,
  county,
  date_s
FROM (
  SELECT date_mdy,
    county,
    date_s 
  FROM air_quality2
  GROUP BY county, date_s ,date_mdy 
  ORDER BY county, date_s
) AS t1 
GROUP BY county, date_s 
ORDER BY date_s;


this returns



I want the county names to be the column headers. I know there is a crosstab function and I have seen the many posts on here where they use it but I cannot get it to work on this query.
As I said, simplify it using count(DISTINCT...)

SELECT county,
  date_s,
  count(DISTINCT date_mdy) AS unique_date_count
FROM air_quality2
GROUP BY county,
  date_s
ORDER BY 1,2;


Now wrap it in crosstab

SELECT *
FROM crosstab($$
    SELECT county,
      date_s::int,
      count(DISTINCT date_mdy) AS unique_date_count 
    FROM air_quality2
    GROUP BY county,
      date_s
    ORDER BY 1,2;
  $$,
  $$ SELECT DISTINCT county FROM air_quality2; $$
)
AS ct(
  year               int,
  "Bergen County"    int,
  "Essex County"     int,
  "Hunterdon County" int,
  "Middlesex County" int,
  "Monmouth County"  int,
  "Morris County"    int,
  "Union County"     int
);


Update


forgot to put the row_name year in the definition.
You may have to cast date_s to int
You may have to cast count(DISTINCT...) to int, (or bigint and change the types).
You will have to make sure you gave all the counties in your sample data. Or, paste the results of SELECT DISTINCT county FROM air_quality2;.