In fact, the list of career change is relatively simple with sum and decode function can be, but I encountered the project, do not know the data who design the field is also designed to be a long type, this long is different from Java, the long in Oracle refers to variable long binary data, the longest 2G, Alas, there is no way to convert.
The following is a conversion of hsqldb, which converts a long to a double type, where D.value is a long, and status is an int type, so value needs to be converted
SELECT P.name,p.id,
SUM (DECODE (D.k_name, ' a ', convert (d.value,sql_double), NULL)) as A1,
SUM (DECODE (D.k_name, ' a ', convert (d.value,sql_double), NULL)) as B1,
SUM (DECODE (D.k_name, ' a ', d.status,null)) as A1_status,
SUM (DECODE (D.k_name, ' a ', d.status,null)) as B1_status
From
P left JOIN
D on P.id=d.id
WHERE A in (' A ', ' B ')
GROUP by P.name,p.id
ORDER by Decode (a,null,0,a) DESC LIMIT 0,10
H2 is a memory database, similar to HSQLDB, but performance does not seem to be hsqldb stable
SELECT P.name,p.id,
SUM (DECODE (D.k_name, ' a ', convert (d.value,number), NULL)) as A1,
SUM (DECODE (D.k_name, ' a ', convert (d.value,number), NULL)) as B1,
SUM (DECODE (D.k_name, ' a ', d.status,null)) as A1_status,
SUM (DECODE (D.k_name, ' a ', d.status,null)) as B1_status
From
P left JOIN
D on P.id=d.id
WHERE A in (' A ', ' B ')
GROUP by P.name,p.id
ORDER by Decode (a,null,0,a) DESC LIMIT 0,10
This article is from the "effort Snail" blog, please make sure to keep this source http://newhouse2000.blog.51cto.com/4355310/1536108