mysql - 未付月薪(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 )
但没有用,有什么帮助吗?
解决方案
尝试 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
推荐阅读
- autocad - AutoCAD SCR 文件绘制多段线 - 结果不一致
- reactjs - 在 React 16 中无法通过 this.context 访问 contextType
- scala - 如何将该组列表的功能重新制作为简单递归?
- php - 在 WAMP 和 phppgadmin 上集成 postgreSQL
- javascript - 从 AngularJS 1.5 升级到 1.7 会抛出“无法复制!不支持复制 Window 或 Scope 实例”
- html - DevicePixelRatio 似乎突然与 Windows 比例叠加
- python - 获取二维数组中最近的坐标
- python - 为什么 vgg.prepare() 方法会创建给定图像的 9 个副本?
- python - 用于模式研究的 Python 正则表达式
- php - 如何显示输入数组的验证错误?