首页 > 解决方案 > 未付月薪(mysql +vb.net)

问题描述

我有一个类似的 MySQL 表

NAME  salary amount   month 1   month 2  month 3  month 4
john  300             300       300      0        0
maria 400             400       0        0        0 
tom   380             380       380      380      0

我想在表格或列表视图或类似的视图中查看结果

name    unpaid month    salary amount
john     month 3        300
john     month 4        300
maria    month 2        400
maria    month 3        400
maria    month 4        400
tom      month 4        380

我试过这样的代码:

sql1="select name,month1 from table where month1=0 "
 sql2="select name,month2 from table where month2=0"
 sql3="select name,month3 from table where month3=0"
sql4="select name,month4 from table where month4=0"
Dim Sql = String.Concat(sql1, ";", sql2 ,";",sql2,";",sql4 )

但没有用,有什么帮助吗?

标签: mysqlvb.netselect

解决方案


尝试 UNION mysql 聚合:

sql1="select name,month1 as unpaid_month from table where month1=0 "
sql2="select name,month2 as unpaid_month from table where month2=0"
sql3="select name,month3 as unpaid_month from table where month3=0"
sql4="select name,month4 as unpaid_month from table where month4=0"
Dim Sql = String.Concat(sql1, " UNION ", sql2 ,"UNION ",sql2," UNION ",sql4 

推荐阅读