ijÍâÆóSQL ServerÃæ試題
--> Title : ijÍâÆóSQL ServerÃæ試題
--> Author : wufeng4552
--> Date : 2010-1-15
Question 1£ºCan you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1£ºÕÒ³öµ±ÔµÄÌìÊý
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
Question2£ºCan you use a SQL statement to calculating it!
How can I print "10 to 20" for books that sell for between $10 and $20£¬"unknown" for books whose price is null, and "other" for all other prices?
Answer 2£º
select bookid,
bookname,
price=case when price is null then 'unknown'
when price between 10 and 20 then '10 to 20'
else price
end
from books
Question3£ºCan you use a SQL statement to finding duplicate values!
How can I find authors with the same last name?You can use the table authors in datatabase pubs. I want to get the result as below:
Output:
au_lname number_dups
---------------------------------------- -----------
Ringer 2
(1 row(s) affected)
Answer 3:
select au_lname,
number_dups=count(1)
from authors
group by au_lname
Question4£ºCan you create a cro
Ïà¹ØÎĵµ£º
Ò»¡¢ÅäÖà SQL Server£¬Ê¹Ö®ÔÊÐí CLR ¼¯³É:
¡¡¡¡1.µ¥»÷“¿ªÊ¼”°´Å¥£¬ÒÀ´ÎÖ¸Ïò“ËùÓгÌÐò”¡¢Microsoft SQL Server 2005 ºÍ“ÅäÖù¤¾ß”£¬È»ºóµ¥»÷“ÍâΧӦÓÃÅäÖÃÆ÷”¡£
¡¡¡¡2.ÔÚ SQL Server 2005 ÍâΧӦÓÃÅäÖÃÆ÷¹¤¾ßÖУ¬µ¥»÷“¹¦ÄܵÄÍâΧӦÓÃÅäÖÃÆ÷”¡£
¡¡¡¡3.Ñ¡ÔñÄ ......
ÄãÊÇ·ñÓöµ½¹ý ÏëÔÚ ×Ö·û´®ÀïÃæÐ´ SQLÓï¾ä£¬µ«ÊÇ×ÜÊÇÓöµ½ ijЩ·ûºÅ²»»áд.
±ÈÈç˵ÔÚ×Ö·û´®ÀïÃæÐ´¸ö±äÁ¿.
like: str sql="select * from abc where id= ' "++" ' "
idµÄ±äÁ¿Ó¦ ÏÈÓõ¥ÒýºÅÈ»ºó“+”ºÅ¡£
½ñÌìÓöµ½¸öºÜ³¤µÄSQLÓï¾ä£¬¶øÇÒSQLÓï¾äÀïÃæÇ¶Ì×ÁË×Ö·û´®¡£µ±Ê±¸ù±¾²»»áд ......
1.SELECTÓï¾ä´ÓÊý¾Ý¿âÖÐѡȡÊý¾Ý
SELECT 'ÁÐÃû' from '±íÃû' SELECT list_name from table_name ´Ó '±íÃû' Ñ¡Çø'ÁÐÃû' Êý¾Ý SQL SELECT * from table_name ´Ó '±íÃû' Ñ¡ÇøÈ«²¿Êý¾Ý
2.SELECT ¼ÓWHERE Óï¾ä
SELECT 'ÁÐÃû' from '±íÃû' WHERE 'Ìõ¼þ'
3.SELECT ¼ÓAS Óï¾ä
ʹÓÃAS ¸øÊý¾ÝÖ¸¶¨Ò»¸ö±ðÃû¡£´Ë±ðÃûÓÃÀ´ÔÚ±í´ïʽ ......
1¡¢±í²Ù×÷¡£
1.1 ÏÖÓбíÔö¼Ó×Ö¶Î
alter table TableName add
columnName1 varchar(2) NULL,
columnName2 varchar(2) NULL,
columnName3 varchar(2) NULL
×¢Ò⣺²»ÓüÓColu ......