本文介绍了获取mysql中行和列的交集之间的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到行和列的交集之间的值。

例如,条件是如果Model1和Plan999它应该得到1200值,或者Model1和Plan 1200得到600值。什么是使用mysql作为后端和vb.net作为前端使用的查询。



id |计划999 |计划1200

------------------------------------

Model1 | 1200 | 300

Model2 | 1300 | 600

I want to get the value between the intersection of row and column.
For example, the condition is if Model1 and Plan999 it should get 1200 value or if Model1 and Plan 1200 get 600 value. what is the query to use using mysql as backend and vb.net as frontend.

id | Plan 999 | Plan 1200
------------------------------------
Model1 | 1200 | 300
Model2 | 1300 | 600

推荐答案

'inputs 
Dim id As String = "Model1"
Dim plan999 As Integer = 1200
Dim plan1200 As Integer = 0
'based on inputs try to select the columns which you want and also change the where condition based on the condition 
Dim sql As String = "select id, CASE when @Plan999 = 0 then [Plan 1200] else [Plan 999] END CASE from TableName where id =@id and (@Plan999 = 0 Or [Plan 999] = @Plan999) and (@Plan1200 = 0 Or [Plan 1200] = @Plan1200)"
' create SqlCommand with about sql and set the parameter value 
'Finally execute it and take the results.



希望这有助于您开始使用


Hope this will help you to get started


这篇关于获取mysql中行和列的交集之间的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 16:34