单行到多列和行

时间:2015-06-17 14:04:08

标签: sql sql-server unpivot

我有一个名为Test的SQL Server表,其中包含以下示例数据:

LineNo  BaseJanuary BaseFebruary    BudgetJanuary   BudgetFebruary
1       10000       20000           30000           40000
2       70000       80000           90000           100000

我想在SQL Server视图(或临时表等)中创建以下结构,但我被卡住......任何想法/建议都将不胜感激!

LineNo  Month       Base    Budget
1       January     10000   30000
2       January     70000   90000
1       February    20000   40000
2       February    80000   100000

注意:这些数字仅供参考,数据是动态的。

3 个答案:

答案 0 :(得分:4)

select LineNo,
       'January' as Month,
       BaseJanuary as Base,
       BudgetJanuary as Budget
  from test
union
select LineNo,
       'February' as Month,
       BaseFebruary as Base,
       BudgetFebruary as Budget
  from test
 order by LineNo, Month

答案 1 :(得分:4)

CROSS APPLY可用于TID: [0] [ESB] [2015-06-17 16:20:22,110] ERROR {org.apache.synapse.config.xml.FilterMediatorFactory} - Invalid attribute values for source and/or regex specified {org.apache.synapse.config.xml.FilterMediatorFactory} TID: [0] [ESB] [2015-06-17 16:20:22,110] ERROR {org.wso2.carbon.sequences.SequenceDeploymentInterceptor} - Sequence Deployment from the file : /usr/local/wso2esb-worker/repository/deployment/server/synapse-configs/default/sequences/documentaleWorkerSequence.xml : Failed. {org.wso2.carbon.sequences.SequenceDeploymentInterceptor} org.apache.synapse.SynapseException: Invalid attribute values for source and/or regex specified at org.apache.synapse.config.xml.AbstractMediatorFactory.handleException(AbstractMediatorFactory.java:213) at org.apache.synapse.config.xml.FilterMediatorFactory.createSpecificMediator(FilterMediatorFactory.java:94) at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91) at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:223) at org.apache.synapse.config.xml.AbstractListMediatorFactory.addChildren(AbstractListMediatorFactory.java:41) at org.apache.synapse.config.xml.SequenceMediatorFactory.createSpecificMediator(SequenceMediatorFactory.java:87) at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91) at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:223) at org.apache.synapse.config.xml.MediatorFactoryFinder.getObjectFromOMNode(MediatorFactoryFinder.java:253) at org.apache.synapse.registry.AbstractRegistry.getResource(AbstractRegistry.java:155) at org.apache.synapse.config.SynapseConfiguration.getSequence(SynapseConfiguration.java:505) at org.apache.synapse.mediators.base.SequenceMediator.init(SequenceMediator.java:300) at org.apache.synapse.mediators.AbstractListMediator.init(AbstractListMediator.java:127) at org.apache.synapse.mediators.base.SequenceMediator.init(SequenceMediator.java:289) at org.apache.synapse.deployers.SequenceDeployer.deploySynapseArtifact(SequenceDeployer.java:64) at org.wso2.carbon.sequences.SequenceDeploymentInterceptor.deploySynapseArtifact(SequenceDeploymentInterceptor.java:42) at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:192) at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136) at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807) at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144) at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377) at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254) at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371) at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59) at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:79) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:124) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) TID: [0] [ESB] [2015-06-17 16:20:22,111] ERROR {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - Deployment of the Synapse Artifact from file : /usr/local/wso2esb-worker/repository/deployment/server/synapse-configs/default/sequences/documentaleWorkerSequence.xml : Failed! {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} org.apache.synapse.deployers.SynapseArtifactDeploymentException: Sequence Deployment from the file : /usr/local/wso2esb-worker/repository/deployment/server/synapse-configs/default/sequences/documentaleWorkerSequence.xml : Failed. at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:473) at org.apache.synapse.deployers.SequenceDeployer.deploySynapseArtifact(SequenceDeployer.java:80) at org.wso2.carbon.sequences.SequenceDeploymentInterceptor.deploySynapseArtifact(SequenceDeploymentInterceptor.java:42) at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:192) at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136) at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807) at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144) at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377) at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254) at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371) at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59) at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:79) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:124) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: org.apache.synapse.SynapseException: Invalid attribute values for source and/or regex specified at org.apache.synapse.config.xml.AbstractMediatorFactory.handleException(AbstractMediatorFactory.java:213) at org.apache.synapse.config.xml.FilterMediatorFactory.createSpecificMediator(FilterMediatorFactory.java:94) at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91) at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:223) at org.apache.synapse.config.xml.AbstractListMediatorFactory.addChildren(AbstractListMediatorFactory.java:41) at org.apache.synapse.config.xml.SequenceMediatorFactory.createSpecificMediator(SequenceMediatorFactory.java:87) at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91) at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:223) at org.apache.synapse.config.xml.MediatorFactoryFinder.getObjectFromOMNode(MediatorFactoryFinder.java:253) at org.apache.synapse.registry.AbstractRegistry.getResource(AbstractRegistry.java:155) at org.apache.synapse.config.SynapseConfiguration.getSequence(SynapseConfiguration.java:505) at org.apache.synapse.mediators.base.SequenceMediator.init(SequenceMediator.java:300) at org.apache.synapse.mediators.AbstractListMediator.init(AbstractListMediator.java:127) at org.apache.synapse.mediators.base.SequenceMediator.init(SequenceMediator.java:289) at org.apache.synapse.deployers.SequenceDeployer.deploySynapseArtifact(SequenceDeployer.java:64) ... 19 more 数据:

UNPIVOT

答案 2 :(得分:0)

private static final int SOCKET_TIMEOUT_MS = 1000 * 10; //default is 2500

strReq.setRetryPolicy(new DefaultRetryPolicy(
            SOCKET_TIMEOUT_MS,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));