I need some help with t-sql and I am new to SQL scripting.
I have a table with little over 70 columns and it is a datawarehouse. Some of values from the feeds are unknown values. For ex: if a date value is unknown, it will be 19000101 and emailkey = -1, while the default value might be NULL.
I need to write a script that retrieves the following information
Column 1 = Name of the column [This can be hard-coded or retrieved from a temp table]
Column 2 = the value that has the highest frequency of occurrence. [It can be NULL, a default value or some other valid value]. It will be the result of the following query: SELECT top 1 HotelKey AS countvalue from dbo.factBooking GROUP by HotelKey ORDER by count(*) desc
Column 3 = The count of the most frequently occurring value]. It will be the result of the following query: SELECT top 1 count() AS countvalue from dbo.factBooking GROUP by HotelKey ORDER by count() desc
Column 4 = This should show the percentage of column 3 against the total count]. It will be the result of the following query: (SELECT top 1 count()from dbo.factBooking GROUP by HotelKey ORDER by count() desc)/( SELECT count(*)from dbo.factBooking)
I want the query to compute the above value for all the columns in the table. Please let me know if I am not clear or if you need more information.