MySQL连接表ON CASE

时间:2016-11-23 07:24:54

标签: php mysql

我正在尝试SELECT * FROM user_settings LEFT JOIN CASE WHEN invoice_address = 0 THEN companies WHEN invoice_address = 1 THEN users END AS table_to_join ON table_to_join.id = invoice_id WHERE user_settings.user_id = :id 基于列值的表格。

SQL我试过:

if($results['invoice_address'] == "0"){
  $sql = "SELECT * FROM users WHERE user_id = :id";
}else if($results['invoice_address'] == "1"){
  $sql = "SELECT * FROM companies WHERE user_id = :id"
}

目前,我使用PHP检查值是否等于某事,然后执行第二个查询:

string json;     
IList<double> d = new List<double> {1.1, double.NaN, double.PositiveInfinity};

json = JsonConvert.SerializeObject(d);

// [1.1,"NaN","Infinity"]

json = JsonConvert.SerializeObject(d, new JsonSerializerSettings {FloatFormatHandling = FloatFormatHandling.Symbol});  

// [1.1,NaN,Infinity]

json = JsonConvert.SerializeObject(d, new JsonSerializerSettings {FloatFormatHandling = FloatFormatHandling.DefaultValue});  

// [1.1,0.0,0.0]

0 个答案:

没有答案