---
title: "SQL sentence"
author: "genius"
date: "2011-09-05T18:13:38Z"
tags: []
categories: ["数据库"]
slug: "sql-sentence"
draft: false
lastmod: "2011-09-05T18:13:38Z"
id: 1166033
url: "https://genius.iteye.com/blog/1166033"
---

select d.id as ValueId,  
                         d.domain\_code as DomainCode,  
                         ls.value\_type as ValueType,   
                     case when v.key\_code is null then d.domain\_code  
                          when length(v.key\_code)&gt;0 then ls.key\_code  
                     end  as KeyCode     ,  
                     case when  v.row\_key is null  then '1'  
                          when  length(v.row\_key)&gt;0  then v.row\_key  
                     end as RowKey,  
                     v.value as value,  
                     d.domain\_value\_type as DomainType  
                      from                           
                          eia\_draft\_domain\_topic dt left join  eia\_draft\_domain d  
                          on dt.draft\_domain\_code = d.domain\_code left join eia\_draft\_list ls  
                          on d.domain\_code=ls.domain\_code left join eia\_draft\_values v  
                          on v.domain\_code = d.domain\_code  
                          and v.topic\_code=dt.draft\_topic\_code  
                          and v.draft\_project\_id=406,  
                          eia\_draft\_project\_topic pt,  
                          eia\_draft\_topic t  
                      WHERE    
                          pt.topic\_code = t.topic\_code  
                      and dt.draft\_topic\_code=t.topic\_code  
                      and t.topic\_code = '01'  
                      and pt.draft\_project\_id=406