lqxue

          常用鏈接

          統計

          book

          tools

          最新評論

          mysql 行變列的例句

          select distinct item.reportoid, item.lineoid,  item.accountoid, sun.amount, mon.amount, tue.amount, wes.amount, thur.amount, fri.amount, sat.amount
          from expenseitem item
          left join (select reportoid, accountoid, lineoid, amount, itemDate from expenseitem
           where itemDate = '2007-11-04' ) sun
           on item.reportoid = sun.reportoid and
            item.accountoid = sun.accountoid and
            item.lineoid = sun.lineoid and
            item.itemDate = sun.itemDate
          left join (select reportoid, accountoid,  lineoid, amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 1) ) mon
           on item.reportoid = mon.reportoid and
            item.accountoid = mon.accountoid and
            item.lineoid = mon.lineoid and
            item.itemDate = mon.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 2)) tue
           on item.reportoid = tue.reportoid and
            item.accountoid = tue.accountoid and
            item.lineoid = tue.lineoid and
            item.itemDate = tue.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 3)  ) wes
           on item.reportoid = wes.reportoid and
            item.accountoid = wes.accountoid and
            item.lineoid = wes.lineoid and
            item.itemDate = wes.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 4)  ) thur
           on item.reportoid = thur.reportoid and
            item.accountoid = thur.accountoid and
            item.lineoid = thur.lineoid and
            item.itemDate = thur.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 5)  ) fri
           on item.reportoid = fri.reportoid and
            item.accountoid = fri.accountoid and
            item.lineoid = fri.lineoid and
            item.itemDate = fri.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 6) ) sat
           on item.reportoid = sat.reportoid and
            item.accountoid = sat.accountoid and
            item.lineoid = sat.lineoid and
            item.itemDate = sat.itemDate
          where item.reportoid = 3712
          order by reportoid, accountoid;

          posted on 2008-07-08 10:52 lqx 閱讀(647) 評論(0)  編輯  收藏 所屬分類: database

          主站蜘蛛池模板: 霍州市| 抚松县| 卢湾区| 宁阳县| 林周县| 图木舒克市| 太康县| 韶关市| 宿州市| 文水县| 宝鸡市| 黔江区| 吉安县| 棋牌| 襄城县| 田阳县| 扎鲁特旗| 汽车| 年辖:市辖区| 莲花县| 黔南| 彭泽县| 云安县| 呼伦贝尔市| 西城区| 井冈山市| 高州市| 张掖市| 新晃| 大埔区| 社会| 张家川| 剑川县| 仁布县| 九寨沟县| 开阳县| 莱阳市| 诸暨市| 稷山县| 郁南县| 新民市|