Practice Activity: Adding the column from one query into another query in SQL Server.

preview_player
Показать описание
How can you combine the columns of two queries together?
My SQL Server Udemy courses are:
----
There are multiple ways to combine the columns of queries together.
One way is by using a correlated query. Another way is to add a second calculation.

If you want to do this as a Practice Activity, then here's the original code.
The original query is (with a minor modification, so I can post it here):

SELECT type_desc, COUNT(*) AS NumberOfObjects
GROUP BY type_desc

SELECT type_desc, COUNT(*) AS NumberOfObjectsIn2022
WHERE YEAR(create_date) = 2022
GROUP BY type_desc

----
Links to my website are:
Рекомендации по теме
Комментарии
Автор

Which keyboard do you use?Can you please tell the model
Thanks

usamaismail-ur
Автор

Hi, Its a great platform to learn and enhance SQL skillset. Here I'm struggling to convert below SAS code into T-SQL, could you please help me in this -

SAS Code:
Data A2; Set A1;
nwords = CountW(HCC_LIST, ', ');
i = 1;
ind = 'N';
Do i = 1 To nwords;
If HCC = '' Then Do;
ind = 'Y';
unique_hcc = 'N';
End;
Else if Scan(HCC_LIST, i, ', ') Trim(HCC) Then Do;
ind = 'Y';
unique_hcc = 'N';
End;
If i > nwords And ind = 'N' Then Do;
unique_hcc = 'Y';
Drop nwords i ind;
Output;
End;
Run;

Sample Input Data (A1):
ID HCC HCC_LIST
123 35 16, 128, 35, 185
123 16, 128, 35, 185
123 116 16, 128, 35, 185
123 128 16, 128, 35, 185

Sample Output Data (A2):
ID HCC HCC_LIST Unique_HCC
123 35 16, 128, 35, 185 N
123 16, 128, 35, 185 N
123 116 16, 128, 35, 185 Y
123 128 16, 128, 35, 185. N

chiroop