Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLʵÀý

--1¡¢²éÕÒÔ±¹¤µÄ±àºÅ¡¢ÐÕÃû¡¢²¿ÃźͳöÉúÈÕÆÚ£¬Èç¹û³öÉúÈÕÆÚΪ¿ÕÖµ£¬ÏÔʾÈÕÆÚ²»Ïê,²¢°´²¿ÃÅÅÅÐòÊä³ö,ÈÕÆÚ¸ñʽΪyyyy-mm-dd¡£
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'ÈÕÆÚ²»Ïê') birthday
from employee
order by dept
--2¡¢²éÕÒÓëÓ÷×ÔÇ¿ÔÚͬһ¸öµ¥Î»µÄÔ±¹¤ÐÕÃû¡¢ÐԱ𡢲¿ÃźÍÖ°³Æ
select emp_no,emp_name,dept,title
from employee
where emp_name'Ó÷×ÔÇ¿' and dept in
(select dept from employee
where emp_name='Ó÷×ÔÇ¿')
--3¡¢°´²¿ÃŽøÐлã×Ü£¬Í³¼Æÿ¸ö²¿ÃŵÄ×ܹ¤×Ê
select dept,sum(salary)
from employee
group by dept
--4¡¢²éÕÒÉÌÆ·Ãû³ÆΪ14´çÏÔʾÆ÷ÉÌÆ·µÄÏúÊÛÇé¿ö£¬ÏÔʾ¸ÃÉÌÆ·µÄ±àºÅ¡¢ÏúÊÛÊýÁ¿¡¢µ¥¼ÛºÍ½ð¶î
select a.prod_id,qty,unit_price,unit_price*qty totprice
from sale_item a,product b
where a.prod_id=b.prod_id and prod_name='14´çÏÔʾÆ÷'
--5¡¢ÔÚÏúÊÛÃ÷ϸ±íÖа´²úÆ·±àºÅ½øÐлã×Ü£¬Í³¼ÆÿÖÖ²úÆ·µÄÏúÊÛÊýÁ¿ºÍ½ð¶î
select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
from sale_item
group by prod_id
--6¡¢Ê¹ÓÃconvertº¯Êý°´¿Í»§±àºÅͳ¼Æÿ¸ö¿Í»§1996ÄêµÄ¶©µ¥×ܽð¶î
select cust_id,sum(tot_amt) totprice
from sales
where convert(char(4),order_date,120)='1996'
group by cust_id
--7¡¢²éÕÒÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id
group by a.cust_id,cust_name
--8¡¢²éÕÒÔÚ1997ÄêÖÐÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'
group by a.cust_id,cust_name
--9¡¢²éÕÒÒ»´ÎÏúÊÛ×î´óµÄÏúÊۼǼ
select order_no,cust_id,sale_id,tot_amt
from sales
where tot_amt=
(select max(tot_amt)
from sales)
--10¡¢²éÕÒÖÁÉÙÓÐ3´ÎÏúÊÛµÄÒµÎñÔ±Ãûµ¥ºÍÏúÊÛÈÕÆÚ
select emp_name,order_date
from employee a,sales b
where emp_no=sale_id and a.emp_no in
(select sale_id
from sales
group by sale_id
having count(*)>=3)
order by emp_name
--11¡¢ÓôæÔÚÁ¿´Ê²éÕÒûÓж©»õ¼Ç¼µÄ¿Í»§Ãû³Æ
select cust_name
from customer a
where not exists
(select *
from sales b
where a.


Ïà¹ØÎĵµ£º

SQL ServerÊý¾Ý¿â¸÷¶ÔÏóµÄ×î´óÈÝÁ¿ËµÃ÷

ϱí˵Ã÷ÔÚ Microsoft SQL Server Êý¾Ý¿âÖж¨ÒåµÄ£¬»òÔÚ Transact-SQL
Óï¾äÖÐÒýÓõĸ÷ÖÖ¶ÔÏóµÄ×î´óÖµ£¨ÊýÁ¿»ò´óС£©¡£ÏÂ±í²»°üº¬ Microsoft® SQL Server 2000™ Windows® CE °æ¡£
 
×î´óÖµ£¨ÊýÁ¿»ò´óС£©
¶ÔÏó
SQL Server 7.0
SQL Server 2000
Åú´¦Àí´óС
65,536 * ÍøÂçÊý¾Ý°ü´óС1
65,536 * Í ......

sql·ÖÒ³

declare @p int
declare @p1 int
declare @count int
set @p=0
set @p1=10
set @count=2
if(@count<>0 or @count<>1)
set @p=@p1*@count-10
SELECT [t1].[userid], [t1].[username], [t1].[userorder]
from (
    SELECT ROW_NUMBER() OVER (ORDER BY [t0].[userorder]) AS [ROW_NU ......

sql ²éѯ

ÓÐÒÔ϶þÕÅ±í£º
Õþµ³±í£ºÕþµ³ID£¬Õþµ³Ãû³Æ
ÒéÔ±±í£ºÒéÔ±ID£¬ÒéÔ±Ãû³Æ£¬Õþµ³ID
ÒªÇó²éѯËùÓеÄÕþµ³ÐÅÏ¢£¬°üº¬£ºÕþµ³Ãû³Æ£¬ÒéÔ±ÈËÊý£¬²¢°´ÒéÔ±ÈËÊýµÄ½µÐòÅÅÁУ¨²»¿ÉÒÔÓÃ×Ó²éѯ£©¡£
Õý½â:
SELECT a.name,
  COUNT(b.id) AS counts
  from zhen a
left join
  yi b
on a.id=b.zhenid
GROUP ......

ÈçºÎд¸ßЧµÄÅúÁ¿²åÈëºÍɾ³ýsqlÓï¾ä

×÷Õߣº²»Ïê ³ö´¦£ºÍøÂçתÔØ  2009/11/18 10:35:22 ÔĶÁ 109  ´Î
¡¡¡¡¼¼Êõˮƽ×ÜÄÜÔÚ³¶Æ¤ºÍ´µÃ«Çó´ÃÖеõ½Ìá¸ß¡£Èç¹û´ÓÀ´²»“Çó´Ã”£¬¿ÉÄܾͲ»»áÖªµÀif(str != "")²»Èçif(str != string.Empty)¸ßЧ¡¢ÅúÁ¿²åÈëºÍɾ³ýµÄsqlÓï¾äÊÇÒªÄÇÑùд²ÅÖ´ÐÐ×î¿ì¡¢½Ó¿ÚºÍ³éÏóÀàµÄÇø±ð²»½öÊÇÓïÑÔ²ãÃæ¡¢ ......

MySQL Ñϸñģʽ sql_mode

ËäȻ˵ÎÒÃǾ¡Á¿ÔÚд³ÌÐòµÄʱºò¿ØÖƲåÈëµ½Êý¾Ý¿âµÄÊý¾Ý£¬¶ø²»ÒªÓÃÊý¾Ý¿âÈ¥ÅжÏÊý¾ÝµÄ¶Ô´í£¬µ«ÊÇÓÐʱºòΪÁË·½±ã»¹ÊÇÐèÒªÊý¾Ý¿â×ÔÉíµÄÈÝ´íÄÜÁ¦À´°ïÖúÎÒÃǴﵽĿµÄµÄ¡£¾ÙÀý˵Ã÷£º
´´½¨ÈçÏÂÊý¾Ý±í
CREATE TABLE `book` (
  `id` int(11) default NULL,
  `num` int(11) unsigned default NULL
) ENGINE=InnoDB DE ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ