在Satement的情况下使用SubQuery(Using SubQuery in case Satement)
我的任务是创建一个查询来从今天的日期提取员工信息。 现在我有测试数据,为下面的每个条件返回一条记录。 如果子查询返回多条记录怎么办? 有没有更好的方法来写这个?
查询Employee_Master。
我需要显示名称,ID,类型和日期。
Type将成为case语句创建的列。
当Start_Date = Today_Date时,Start_Date = Today_Date'TERMINATED'当'Start_Date <> Today_Date和Terminate_Date <> Today_Date时,当Start_Date = Today_Date'TERMINATED'时,今日的employee_reference表中存在相同的记录。 如果用户是'EXTENDED'并且存在于Name_Change表中,则“NAME CHANGED”
SELECT Name, ID, Date, Type = CASE WHEN Start_Date = Today_Date THEN 'NEW' WHEN Terminate_Date = Today_Date THEN 'TERMINATED' WHEN ID = (SELECT A.ID FROM Employee_Master AS A INNER JOIN Employee_Reference AS B on B.ID = A.ID WHERE DATE = GETDATE()) THEN 'EXTENDED' WHEN ID = (SELECT A.ID FROM Employee_Master AS A INNER JOIN Name_Change AS B ON B.ID = A.ID WHERE Create_Date = GETDATE()) THEN 'Name Changed' END FROM Employee_Master WHERE Today_Date = GETDATE()
I'm tasked with creating a query to pull Employee information from today's date. Right now I have test data that returns one record for each of the conditions below. What if the subquery returns multiple records? Is there a better way to write this?
Query Employee_Master.
I need to display the Name, ID, Type, and Date.
Type is going to be a column created by a case statement.
'NEW' when Start_Date = Today_Date 'TERMINATED' when Terminate_Date = Today_Date 'EXTENDED' when Start_Date<>Today_Date and Terminate_Date<>Today_Date and the same record exists in employee_reference table for today's date. 'NAME CHANGED' if the user is 'EXTENDED' and exists in Name_Change table
SELECT Name, ID, Date, Type = CASE WHEN Start_Date = Today_Date THEN 'NEW' WHEN Terminate_Date = Today_Date THEN 'TERMINATED' WHEN ID = (SELECT A.ID FROM Employee_Master AS A INNER JOIN Employee_Reference AS B on B.ID = A.ID WHERE DATE = GETDATE()) THEN 'EXTENDED' WHEN ID = (SELECT A.ID FROM Employee_Master AS A INNER JOIN Name_Change AS B ON B.ID = A.ID WHERE Create_Date = GETDATE()) THEN 'Name Changed' END FROM Employee_Master WHERE Today_Date = GETDATE()
原文:https://stackoverflow.com/questions/31571051
最满意答案
.xlsx
是Excel 2007中引入的格式。因此,如果没有安装适当的插件(如果您的版本有一个插件),可以通过以前的版本读取它
.xlsx
is a format introduced in Excel 2007. So it can be read by previous versions without proper plug-in installed (if there is one for your version)
相关问答
更多-
看来除了RGB之外我还应该添加色调属性的设置。 back_XSSFColor_out.setTint(back_XSSFColor_in.getTint()); It appeared I should add setting of tint property in addition to RGB. back_XSSFColor_out.setTint(back_XSSFColor_in.getTint());
-
使用Apache POI写入excel会破坏excel文件(Writing to an excel using Apache POI corrupts the excel file)[2022-03-30]
创建工作表,行和单元格后,需要将excel写入磁盘。 public WriteExcel(String FilePath) throws IOException { this.FilePath=FilePath; } //Write to a specific Cell public void writeToCell(String SheetName, int RowNum, int ColNum, String Data) throws IOException { fout=new ... -
这将做的工作: Workbook wb = WorkbookFactory.create(myExcelFile); 然后你可以检查工厂创建的确切类型: if (wb instanceof HSSFWorkbook) { // do whatever } else if (wb instanceof SXSSFWorkbook) { // do whatever } else if (wb instanceof XSSFWorkbook) { // do whatever } 无 ...
-
好吧,经过一些研究,我终于修复了它。 就像更新一样,即使你在Excel中打开文件>>打开,这个错误也会出现,所以这不是我的程序导致错误。 事实证明,我的测试台在Office 2007安装中遇到了一些遗留问题。 它试图用Office 2007打开.xlsx文件,即使它已经不再安装了。 我进入控制面板>>文件夹选项>>文件类型,并将.xlsx更改为Microsoft开放XML转换器,它工作正常! Alright so after some more research I finally fixed it. Ju ...
-
是的,它会! MS的东西不是POI lib的依赖。 否则,支持Poi的所有应用程序都必须部署到Windows机器上,这真是一场噩梦! yes it will! MS stuffs are not dependencies of POI lib. Otherwise, all applications with Poi supported must be deployed to a Windows machine, what a nightmare!
-
Apache POI阅读xlsx NPE(Apache POI Read xlsx NPE)[2023-05-21]
所有行都没有Row对象。 考虑一下,当您在Excel中启动新电子表格时,最多可以有1,048,576行,但保存空电子表格会导致文件大小变小。 也就是说,对不存在的行的引用将导致绝对巨大的文件。 只有在存在与它们相关联的某种内容时才应存储对行的引用 - 任何单元格值,格式,边框等。行可能显示为空白但有一些格式或者可能用于使内容现在消失。 Cell连续有一个类似的论点。 对于甚至不使用的单元格,没有理由使用Cell引用。 但是你可以删除Cell的内容,而不是删除Cell本身; 它可以是CELL_TYPE_BLA ... -
Apache POI:xlsx无法使用MS Office excel打开文件(Apache POI : xlsx not opening the file with MS Office excel)[2023-10-02]
.xlsx是Excel 2007中引入的格式。因此,如果没有安装适当的插件(如果您的版本有一个插件),可以通过以前的版本读取它 .xlsx is a format introduced in Excel 2007. So it can be read by previous versions without proper plug-in installed (if there is one for your version) -
Apache poi XLSX到XLS(Apache poi XLSX to XLS)[2023-11-24]
我同意中心答案,但我想添加几行代码。 您说您正在使用XSSF实现。 因此,对于要保存的工作簿,请执行以下更改:更改XSSFWorkbook x = new XSSFWorkbook(); 到Workbook x = new HSSFWorkbook(); 从org.apache.poi.ss.usermodel.Workbook;导入Workbook的位置org.apache.poi.ss.usermodel.Workbook; 同样改变XSSFRow实例化 XSSFRow r = newXSSF(); ... -
Apache POI创建xlsx文件,以后无法打开。(Apache POI creates xlsx file which it can't open later. Zip bomb detected)[2023-11-16]
只需按照错误消息的建议操作,并通过不同的方式设置限制 ZipSecureFile.setMinInflateRatio(0) 您似乎有一个相当特殊的用例,它生成的文件与恶意用户可能用来使服务器崩溃,使用CPU或内存不足的文件相似。 为了避免这种情况,Apache POI具有此限制,但可以根据需要进行不同的设置。 因此,如果文件不是来自不受信任的用户,则可以轻松调整这些限制以避免出现错误消息。 Excel或LibreOffice可能比Apache POI更优化文件内容,从而生成未达到这些限制的文件。 Simp ... -
您需要以下给定的jar文件来导出xlsx文件。 poi-3.9-20121203.jar poi-ooxml-3.9-20121203.jar poi-ooxml-schemas-3.9-20121203.jar 请注意,您必须使用SXSSF (Streaming Usermodel API)来解决Java堆空间问题。 You need the below given jar files to export xlsx files. poi-3.9-20121203.jar poi-ooxml-3.9-20 ...