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

哪位高手能看明白这句sql是什么意思.好难啊

2012-08-30 
谁能看明白这句sql是什么意思....好难啊~SELECTProvinces.Pr_name,CityRefer.cr_name,BasicOffice.bo_name

谁能看明白这句sql是什么意思....好难啊~
SELECT Provinces.Pr_name, 
  CityRefer.cr_name, 
  BasicOffice.bo_name, 
  JdName.jd_name, 
  Equipment.sb_no, 
  ISNULL(derivedtbl_2.sumalldata, 0) AS sumalldata, 
  ISNULL(derivedtbl_2.suminperioddata, 0) AS suminperioddata, 
  Equipment.sb_state, 
  Equipment.sb_position, 
  Equipment.sb_person, 
  Equipment.sb_tel, 
  Equipment.sb_coordinates, 
  ISNULL(derivedtbl_2.meterscount, 0) AS meterscount, 
  ISNULL(derivedtbl_2.Alerted, 0) AS Alerted 
 FROM (
SELECT MetersName_Ori.ConcentrationID, 
COUNT(derivedtbl_1.mn_id) AS meterscount, 
SUM(MetersName_Ori.AccuData) AS sumalldata, 
SUM(derivedtbl_1.SumDataAdd) AS suminperioddata, 
ISNULL(MAX(MetersName_Ori.Alerted), 0) AS Alerted 
FROM (SELECT SumDataAdd, mn_id FROM dbo.MetersDataSumByPastMonth(0) AS MetersDataSumByPastMonth_1) 
AS derivedtbl_1 
INNER JOIN MetersName_Ori ON derivedtbl_1.mn_id = MetersName_Ori.id 
GROUP BY MetersName_Ori.ConcentrationID) 
  AS derivedtbl_2 
  RIGHT OUTER JOIN Equipment ON derivedtbl_2.ConcentrationID = Equipment.sb_no 
  INNER JOIN BasicOffice ON Equipment.cr_id = BasicOffice.cr_id AND Equipment.bo_id = BasicOffice.bo_id AND Equipment.pr_id = BasicOffice.pr_id 
  INNER JOIN Provinces ON Equipment.pr_id = Provinces.Pr_id 
  INNER JOIN CityRefer ON Equipment.cr_id = CityRefer.cr_id AND Equipment.pr_id = CityRefer.pr_id 
  INNER JOIN JdName ON Equipment.pr_id = JdName.pr_id AND Equipment.cr_id = JdName.cr_id AND 
Equipment.bo_id = JdName.bo_id AND Equipment.jd_id = JdName.jd_id

[解决办法]
帮你整理一下,LZ如果知道这几个表示什么意思,大概就知道这个语句的含义了。 

SQL code
SELECT  Provinces.Pr_name ,        CityRefer.cr_name ,        BasicOffice.bo_name ,        JdName.jd_name ,        Equipment.sb_no ,        ISNULL(derivedtbl_2.sumalldata, 0) AS sumalldata ,        ISNULL(derivedtbl_2.suminperioddata, 0) AS suminperioddata ,        Equipment.sb_state ,        Equipment.sb_position ,        Equipment.sb_person ,        Equipment.sb_tel ,        Equipment.sb_coordinates ,        ISNULL(derivedtbl_2.meterscount, 0) AS meterscount ,        ISNULL(derivedtbl_2.Alerted, 0) AS AlertedFROM    ( SELECT    MetersName_Ori.ConcentrationID ,                    COUNT(derivedtbl_1.mn_id) AS meterscount ,                    SUM(MetersName_Ori.AccuData) AS sumalldata ,                    SUM(derivedtbl_1.SumDataAdd) AS suminperioddata ,                    ISNULL(MAX(MetersName_Ori.Alerted), 0) AS Alerted          FROM      ( SELECT    SumDataAdd ,                                mn_id                      FROM      dbo.MetersDataSumByPastMonth (0) AS MetersDataSumByPastMonth_1                    ) AS derivedtbl_1                    INNER JOIN MetersName_Ori ON derivedtbl_1.mn_id = MetersName_Ori.id          GROUP BY  MetersName_Ori.ConcentrationID        ) AS derivedtbl_2        RIGHT OUTER JOIN Equipment ON derivedtbl_2.ConcentrationID = Equipment.sb_no        INNER JOIN BasicOffice ON Equipment.cr_id = BasicOffice.cr_id                                  AND Equipment.bo_id = BasicOffice.bo_id                                  AND Equipment.pr_id = BasicOffice.pr_id        INNER JOIN Provinces ON Equipment.pr_id = Provinces.Pr_id        INNER JOIN CityRefer ON Equipment.cr_id = CityRefer.cr_id                                AND Equipment.pr_id = CityRefer.pr_id        INNER JOIN JdName ON Equipment.pr_id = JdName.pr_id                             AND Equipment.cr_id = JdName.cr_id                             AND Equipment.bo_id = JdName.bo_id                             AND Equipment.jd_id = JdName.jd_id 


[解决办法]

SQL code
SELECT Provinces.Pr_name,       CityRefer.cr_name,       BasicOffice.bo_name,       JdName.jd_name,       Equipment.sb_no,       Isnull(derivedtbl_2.sumalldata, 0)      AS sumalldata,       Isnull(derivedtbl_2.suminperioddata, 0) AS suminperioddata,       Equipment.sb_state,       Equipment.sb_position,       Equipment.sb_person,       Equipment.sb_tel,       Equipment.sb_coordinates,       Isnull(derivedtbl_2.meterscount, 0)     AS meterscount,       Isnull(derivedtbl_2.Alerted, 0)         AS AlertedFROM   (SELECT MetersName_Ori.ConcentrationID,               Count(derivedtbl_1.mn_id)              AS meterscount,               Sum(MetersName_Ori.AccuData)           AS sumalldata,               Sum(derivedtbl_1.SumDataAdd)           AS suminperioddata,               Isnull(Max(MetersName_Ori.Alerted), 0) AS Alerted        FROM   (SELECT SumDataAdd,                       mn_id                FROM   dbo.Metersdatasumbypastmonth(0) AS MetersDataSumByPastMonth_1) AS derivedtbl_1               INNER JOIN MetersName_Ori                       ON derivedtbl_1.mn_id = MetersName_Ori.id        GROUP  BY MetersName_Ori.ConcentrationID) AS derivedtbl_2       RIGHT OUTER JOIN Equipment                     ON derivedtbl_2.ConcentrationID = Equipment.sb_no       INNER JOIN BasicOffice               ON Equipment.cr_id = BasicOffice.cr_id                  AND Equipment.bo_id = BasicOffice.bo_id                  AND Equipment.pr_id = BasicOffice.pr_id       INNER JOIN Provinces               ON Equipment.pr_id = Provinces.Pr_id       INNER JOIN CityRefer               ON Equipment.cr_id = CityRefer.cr_id                  AND Equipment.pr_id = CityRefer.pr_id       INNER JOIN JdName               ON Equipment.pr_id = JdName.pr_id                  AND Equipment.cr_id = JdName.cr_id                  AND Equipment.bo_id = JdName.bo_id                  AND Equipment.jd_id = JdName.jd_id ----5楼看来和我用的同样的第三方格式化工具。能给个 CDKEY否? 

热点排行