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Óï¾ä£¬µ«ÊÇ×ÜÊÇÓöµ½ ijЩ·ûºÅ²»»áд.
±ÈÈç˵ÔÚ×Ö·û´®ÀïÃæÐ´¸ö±äÁ¿.
like: str sql="select * from abc where id= ' "++" ' "
idµÄ±äÁ¿Ó¦ ÏÈÓõ¥ÒýºÅÈ»ºó“+”ºÅ¡£
½ñÌìÓöµ½¸öºÜ³¤µÄSQLÓï¾ä£¬¶øÇÒSQLÓï¾äÀïÃæÇ¶Ì×ÁË×Ö·û´®¡£µ±Ê±¸ù±¾²»»áд ......
¶ÔͬһÕÅ±í½øÐÐÁ½ÖÖ·½Ê½²éѯ£¨½á¹û¼¯Ïàͬ£©£º
case1 ²éѯÌõ¼þ:°üÀ¨¼ÆËã»úÃû£¬êdzƣ¬Ìí¼Óʱ¼äµÈµÈһЩÏÞÖÆÌõ¼þ×ֶΡ£¶øÇÒÐèÁª±í²éѯ±ðµÄ±í
²éѯÊý¾ÝÁ¿£º 100Íò 200Íò
µ¥´¿Ö´ÐÐSQLÓï¾äËùÐèʱ¼ä£º31ºÁÃë&nbs ......
1¡¢±í²Ù×÷¡£
1.1 ÏÖÓбíÔö¼Ó×Ö¶Î
alter table TableName add
columnName1 varchar(2) NULL,
columnName2 varchar(2) NULL,
columnName3 varchar(2) NULL
×¢Ò⣺²»ÓüÓColu ......
ת×Ô£ºhttp://news.newhua.com/news1/program_database/2008/530/0853092638H5D5AAC4I06BI1G22DCAH8H8B7HIGB0G3F109J6E7F9K2_2.html?lt=common
1. Ôʼµ¥¾ÝÓëʵÌåÖ®¼äµÄ¹ØÏµ
¿ÉÒÔÊÇÒ»¶ÔÒ»¡¢Ò»¶Ô¶à¡¢¶à¶Ô¶àµÄ¹ØÏµ¡£ÔÚÒ»°ãÇé¿öÏ£¬ËüÃÇÊÇÒ»¶ÔÒ»µÄ¹ØÏµ£º¼´Ò»ÕÅÔʼµ¥¾Ý¶ÔÓ¦ÇÒÖ»¶ÔÓ¦Ò»¸öʵÌå¡£ÔÚÌØÊâÇé¿öÏ£¬ËüÃÇ¿ÉÄÜÊÇÒ»¶Ô¶ ......