首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

百分求SQL语句,该怎么解决

2012-01-10 
百分求SQL语句DROPTABLEIFEXISTS`customertemplate`CREATETABLEIFNOTEXISTScustomertemplate (CID in

百分求SQL语句
DROP   TABLE   IF   EXISTS   `customertemplate`;
CREATE   TABLE   IF   NOT   EXISTS   "customertemplate "   (
    "CID "   int(11)   NOT   NULL,
    "CustomerID "   int(11)   NOT   NULL,
    "TemplateID "   int(11)   NOT   NULL,
    "TemplateType "   varchar(10)   NOT   NULL,
    PRIMARY   KEY     ( "CID ")
)   AUTO_INCREMENT=7   ;

--
--   Dumping   data   for   table   `customertemplate`
--

INSERT   INTO   `customertemplate`   (`CID`,   `CustomerID`,   `TemplateID`,   `TemplateType`)   VALUES
(1,   8,   1,   '1 '),
(2,   8,   2,   '2 '),
(3,   8,   3,   '1 '),
(4,   8,   4,   '2,3 '),
(6,   7,   4,   '1 ');

--   --------------------

--
--   Table   structure   for   table   `template`
--

DROP   TABLE   IF   EXISTS   `template`;
CREATE   TABLE   IF   NOT   EXISTS   "template "   (
    "TemplateID "   int(11)   NOT   NULL,
    "TemplateName "   varchar(30)   NOT   NULL,
    "TemplateFileName "   varchar(150)   NOT   NULL,
    PRIMARY   KEY     ( "TemplateID ")
)   AUTO_INCREMENT=6   ;

--
--   Dumping   data   for   table   `template`
--

INSERT   INTO   `template`   (`TemplateID`,   `TemplateName`,   `TemplateFileName`)   VALUES
(1,   'Gloveco ',   'Gloveco '),
(2,   'Medline ',   'Medline '),
(3,   'MedLine   Invoice ',   'invoice_medline '),
(4,   'MedLine   PackingList ',   'PackingList_medline '),
(5,   'Delivery   Order ',   'Delivery   Order ');

select   *   from   template   t   left   join   customertemplate   ct   on   t.TemplateID=ct.TemplateID   where   ct.CustomerID=8  

这样只能查询出来id=8的。
我要显示所有的template,以及在ct表里有的数据,,
TemplateName     TemplateFileName     CID     CustomerID     TemplateID     TemplateType    
    Gloveco                   Gloveco                 1                 8                       1                     1  
    Medline                   Medline                 2                 8                       2                     2  
    MedLine   Invoice   invoice                 3                 8                       3                     1  


MedLine   PackingList   PackingList_medline   4   8                       4                     2,3  
      xx                             xxx                       null         null                 null                 null
      yy                             yy

大概就是这样,有点表达不清。。。
另外,是mysql,尽量给我mysql能支持的答案。。

[解决办法]
觉得你写的对,明天试试
[解决办法]
select * from template t left join customertemplate ct on t.TemplateID=ct.TemplateID and ct.CustomerID=8

热点排行