SQL语句转换成HQL语句
怎么将以下的SQL语句转换成HQL语句:SELECTTA001,TA002,TA006,SUM(TA015-ISNULL(TA017,0))AST1INTO#MOC1FR...
怎么将以下的SQL语句转换成HQL语句:
SELECT TA001,TA002,TA006,SUM(TA015-ISNULL(TA017,0)) AS T1 INTO #MOC1
FROM MOCTA
WHERE TA011 IN ('1','2','3') AND TA013='Y' AND TA010>='20130901' AND TA010<='20130930'
GROUP BY TA001,TA002,TA006
SELECT TB003,SUM(TB004-ISNULL(TB005,0)) AS T2 INTO #MOC2
FROM MOCTB,MOCTA
WHERE TB001=TA001 AND TB002=TA002 AND TA011 IN ('1','2','3') AND TA013='Y'
GROUP BY TB003
SELECT MC001,SUM(ISNULL(MC007,0)) AS T3 INTO #MOC3
FROM INVMC
GROUP BY MC001
SELECT COUNT(*) AS T4
FROM #MOC1,#MOC2,#MOC3
WHERE TA006=TB003 AND TA006=MC001 AND T3>T2
DROP TABLE #MOC1,#MOC2,#MOC3 展开
SELECT TA001,TA002,TA006,SUM(TA015-ISNULL(TA017,0)) AS T1 INTO #MOC1
FROM MOCTA
WHERE TA011 IN ('1','2','3') AND TA013='Y' AND TA010>='20130901' AND TA010<='20130930'
GROUP BY TA001,TA002,TA006
SELECT TB003,SUM(TB004-ISNULL(TB005,0)) AS T2 INTO #MOC2
FROM MOCTB,MOCTA
WHERE TB001=TA001 AND TB002=TA002 AND TA011 IN ('1','2','3') AND TA013='Y'
GROUP BY TB003
SELECT MC001,SUM(ISNULL(MC007,0)) AS T3 INTO #MOC3
FROM INVMC
GROUP BY MC001
SELECT COUNT(*) AS T4
FROM #MOC1,#MOC2,#MOC3
WHERE TA006=TB003 AND TA006=MC001 AND T3>T2
DROP TABLE #MOC1,#MOC2,#MOC3 展开
2个回答
展开全部
你要知道hql语句是针对的对象,而sql语句是对表,hql中一般改写的 查询语句 。所以改起来很容易的,
以第一个为例SELECT TA001,TA002,TA006,SUM(TA015-ISNULL(TA017,0)) AS T1 INTO #MOC1
FROM MOCTA WHERE TA011 IN ('1','2','3') AND TA013='Y' AND TA010>='20130901' AND TA010<='20130930'
GROUP BY TA001,TA002,TA006
可以看出来MOCTA这个表中包含TA001,TA002,TA006等几列,所以你先用hibernate映射成对象的各属性,如Mocta 这个类对应这个表,其中有ta001,ta002,ta006等属性。然后改写成下面:
select m.ta001,m.ta002,sum(m.ta006) from Mocta as m where m.ta001 = '????' and ???
就可以了
以第一个为例SELECT TA001,TA002,TA006,SUM(TA015-ISNULL(TA017,0)) AS T1 INTO #MOC1
FROM MOCTA WHERE TA011 IN ('1','2','3') AND TA013='Y' AND TA010>='20130901' AND TA010<='20130930'
GROUP BY TA001,TA002,TA006
可以看出来MOCTA这个表中包含TA001,TA002,TA006等几列,所以你先用hibernate映射成对象的各属性,如Mocta 这个类对应这个表,其中有ta001,ta002,ta006等属性。然后改写成下面:
select m.ta001,m.ta002,sum(m.ta006) from Mocta as m where m.ta001 = '????' and ???
就可以了
更多追问追答
追问
我这是所有的语句加起来才算一个查询
追答
这些每个都写一个方法,得出来集合你可以经过逻辑处理得到你的所要啊,要不你就把上面的几个语句改写成一个sql来个联合查询,之后再改写成hql也是一样的啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询