sql ѧϰ
Ò»¡¢ÈçºÎ´ÓselectµÄ²éѯ½á¹ûÖÐÔÙ´ÎÔËË㣿
µÚÒ»²½£º
´Ö²éѯ¡£Ê×ÏÈÐèÒª½«µÚÒ»²ã²éѯŪ¶Ô£¬¹ØϵŪÇå³þ¡£
select sum(quantity) total ,price_water,price_pollute from pay_water where time_pay >='2010-02-01 00:00:00.000' and time_pay <'2010-02-28 23:59:59.000'
group by price_water,price_pollute
µÚ¶þ²½£º
¶þ´Î²éѯ¡£ÔÚÒ»´Î²éѯµÄ»ù´¡ÉϽøÐÐÔËËã¡£
select total*price_water a ,total*price_pollute b from (
select sum(quantity) total ,price_water,price_pollute from pay_water where time_pay >='2010-02-01 00:00:00.000' and time_pay <'2010-02-28 23:59:59.000'
group by price_water,price_pollute
) as test
as testÊDZØÐëÓеģ¬Ã»Óоͻᱨ´í¡£
µÚÈý²½£º
ѹËõ£º
select sum(total*price_water) a ,sum(total*price_pollute) b from (
select sum(quantity) total ,price_water,price_pollute from pay_water where time_pay >='2010-02-01 00:00:00.000' and time_pay <'2010-02-28 23:59:59.000'
group by price_water,price_pollute
) as test
sum()º¯Êý¿ÉÒÔ½«ÉÏÏÂѹËõ£¬Çó³ö¸ÃÁеÄ×ܺ͡£
¶þ¡¢group by Óï¾ä¡£
selectÖеÄ×Ö¶ÎÖ»ÄÜÊÇgroup byÖеÄ×ֶλòÕ߾ۺϺ¯Êý¡£
Ïà¹ØÎĵµ£º
JOINÓÅ»¯
MySQLÖÐjoinµÄʵÏÖ²ÉÓõÄÊÇNested Loop JoinËã·¨¡£Í¨¹ýÇý¶¯±íµÄ½á¹û¼¯×÷Ϊѻ·»ù´¡Êý¾Ý£¬È»ºó½«¸Ã½á¹û¼¯ÖеÄÊý¾Ý×÷Ϊ¹ýÂË
Ìõ¼þÒ»ÌõÌõµÄµ½ÏÂÒ»¸ö±íÖвéѯÊý¾Ý£¬×îºóºÏ²¢½á¹û£¬Èç¹û´æÔÚºóÐø±í£¬¹ý³ÌÒ²Èç´Ë¡£
¾¡Á¿¼õÉÙjoinÓï¾äÖÐnested loopÑ»·µÄ´ÎÊý¡£×îÓÐЧµÄ·½·¨ÊÇÈÃÇý¶¯±íµÄ½á¹û¼¯¾¡¿ÉÄܵÄС
ÓÅÏÈÓÅ»¯nested ......
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn= new SqlConnection("server=(local);database=colorring;uid=sa;pwd=;");
conn.Open();
string sqlstr = "exec master..xp_cmdshell 'bcp \"select top 100 * from master..aps\" queryout c:\\aa ......
1¡¢¶¨ÒåÖ¸Á£ºusing System.Data.SqlClient;
2¡¢¶¨ÒåsqlÁ¬½Ó£º SqlConnection conn= new SqlConnection("server=(local);database=colorring;uid=sa;pwd=;");
3¡¢´ò¿ªsqlÁ¬½Ó£º conn.Open();
4¡¢¶¨ÒåsqlÓï¾ä£ºstring sqlstr = "insert into test values (123321)";
5¡¢×é×°sqlÓï¾äºÍÁ¬½Ó£ºSqlCommand cmd = new SqlCo ......
1.ÈçºÎ½«Ò»¸öSQL Server±íµÄ½á¹¹¸´ÖƵ½ÁíÒ»¸öн¨µÄ±íÖÐ
select * into бí from ¾É±í where 0 = 1
2.ÐÞ¸Ä×Ö¶ÎĬÈÏÖµ
alter table ±íÃû add default ĬÈÏÖµ for ×Ö¶ÎÃû
3. È¡µÃÊý¾Ý¿â½á¹¹
SELECT name from sysdatabases
4.Ôö¼ÓÁÐ
......
Ê×ÏÈÔÚsqlserverµÄ°²×°Â·¾¶Ï£¬È磺D:\Program Files\Microsoft SQL
Server\MSSQL\£¬ÕÒµ½ÎļþÃûÊÇscptxfr.exeµÄÎļþ,ÀûÓÃÃüÁîÐй¤¾ß£º¾ßÌåÓ÷¨ÈçÏ£º
D:\PROGRA~1\MICROS~2\MSSQL\>scptxfr/?
ÃüÁîÐÐÓï·¨:
SCPTXFR /s
<·þÎñÆ÷> /d <Êý¾Ý¿â> {[/I] | [/P <ÃÜÂë>]}
&n ......