Forum

Posted by Rıdvan, Feb. 23, 2023, 10:46 a.m.

SQL questions

1-) SELECT TOP 10 CITY,COUNT(DISTINCT CUSTOMERNAME) FROM SALES GROUP BY CITY ORDER BY 2 DESC    

what is the answer of the command

2-) SELECT * FROM CUSTOMERS WHERE ID IN (SELECT CUSTOMERID FROM ADDRESS GROUP BY CUSTOMERID HAVING COUNT(CUSTOMERID)>1)     what is the answer of the command ?

3-)  If 1 million rows of records are entered in a table of type NCHAR(50), how much space does it occupy in memory?

4-) SELECT * FROM CUSTOMER WHERE BIRTHDATE='1980-15-01'    what is the answer of the command

5-)  What type of data constraint is used to set the default value a field can take during data entry?

6-) SELECT NAMESURNAME,GENDER,SUM(TOTALPRICE) AS PRICE FROM SALES WHERE SUM(TOTALPRICE)<1000000 GROUP BY NAMESURNAME,GENDER, ORDER BY 2 DESC,3 ASC    what is the answer of the command ?

7-) What is the SQL query that does a random staff selection in a staff table?

Answers

Hi there,

We are an English forum, can you repost in english?

Oh sorry.  I couldn't find answers to the following questions. Can you help?

1-) SELECT TOP 10 CITY,COUNT(DISTINCT CUSTOMERNAME) FROM SALES GROUP BY CITY ORDER BY 2 DESC    

what is the answer of the command

2-) SELECT * FROM CUSTOMERS WHERE ID IN (SELECT CUSTOMERID FROM ADDRESS GROUP BY CUSTOMERID HAVING COUNT(CUSTOMERID)>1)     what is the answer of the command ?

3-)  If 1 million rows of records are entered in a table of type NCHAR(50), how much space does it occupy in memory?

4-) SELECT * FROM CUSTOMER WHERE BIRTHDATE='1980-15-01'    what is the answer of the command

5-)  What type of data constraint is used to set the default value a field can take during data entry?

6-) SELECT NAMESURNAME,GENDER,SUM(TOTALPRICE) AS PRICE FROM SALES WHERE SUM(TOTALPRICE)<1000000 GROUP BY NAMESURNAME,GENDER, ORDER BY 2 DESC,3 ASC    what is the answer of the command ?

7-) What is the SQL query that does a random staff selection in a staff table?


Topluluk Tarafından Doğrulandı simgesi

Rıdvan, Feb. 23, 2023, 11:21 a.m.

All right, updated your questions in the original post, they are interesting questions, anybody want a give it a try?

Leon, Feb. 23, 2023, 11:54 a.m.
SQLPad user avatar

Leon (949)

Feb. 23, 2023, 11:11 a.m.

Trying out my answers : )

1-) SELECT TOP 10 CITY,COUNT(DISTINCT CUSTOMERNAME) FROM SALES GROUP BY CITY ORDER BY 2 DESC    

# Top 10 cities with the most number of distinct customernames,
# not the number of unique customers count, as people may share the same name.

2-)

SELECT * FROM CUSTOMERS 
WHERE ID IN (
SELECT CUSTOMERID
FROM ADDRESS
GROUP BY CUSTOMERID
HAVING COUNT(CUSTOMERID)>1
)   

# All customers who have more than 1 addresses

3-)  If 1 million rows of records are entered in a table of type NCHAR(50), how much space does it occupy in memory?

Might varies by differnt database, but usually each char takes 2 bytes, so NCHAR(50) is 100 bytes, 1millon rows is roughly 100 megabytes 

4-) SELECT * FROM CUSTOMER WHERE BIRTHDATE='1980-15-01'  

No month in 15, this will return error as the date format is wrong.

5-)  What type of data constraint is used to set the default value a field can take during data entry?

Default

6-)

SELECT NAMESURNAME,GENDER,SUM(TOTALPRICE) AS PRICE 
FROM SALES

WHERE SUM(TOTALPRICE)<1000000
GROUP BY NAMESURNAME,GENDER, ORDER BY 2 DESC,3 ASC   

This query is wrong, instead of WHERE you should use HAVING?

7-) What is the SQL query that does a random staff selection in a staff table?

Need more details

SQLPad user avatar

Lisa (26)

Feb. 23, 2023, 12:50 p.m.