亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP MySQL 僅顯示表中多條記錄的唯一值

PHP MySQL 僅顯示表中多條記錄的唯一值

PHP
墨色風雨 2021-11-05 10:18:23
我很難過,我不知道如何使用多個不同的標識符在表上獲取結果,然后對結果進行分組這是我的表ProjectFieldValue簡而言之id | project_id | textValue      | dateValue  | fieldKey================================================================1  | 1000       | Closed         | NULL       | contract_status================================================================2  | 1000       | NULL           | 2019-05-01 | closing_date================================================================3  | 1001       | Open           | NULL       | contract_status================================================================4  | 1001       | NULL           | 2019-05-22 | closing_date================================================================5  | 1002       | Closed         | NULL       | contract_status================================================================6  | 1002       | NULL           | 2019-05-11 | closing_date================================================================7  | 1003       | Closed         | NULL       | contract_status================================================================8  | 1003       | NULL           | 2019-05-24 | closing_date================================================================我需要運行查詢以獲取所有記錄...“contact_status”的fieldKey和“Open”的fieldKey的textValue“close_date”的fieldKey和2019-05-01 AND 2019-05-30之間的dateValue這是我嘗試過的,我只是得到一個空白的查詢結果集select pfv.* from ProjectFieldValue pfvwhere (pfv.dateValue between '2019-05-01' AND '2019-05-30' AND pfv.fieldKey = 'closing_date') AND (pfv.textValue = 'Closed' AND pfv.fieldKey = 'contract_status')
查看完整描述

2 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

空白是可以的,因為您試圖獲取字段鍵 = 結束日期和字段鍵 = 合同狀態的所有記錄,這是不可能的。


您可以嘗試使用 OR 代替 AND。


喜歡


select pfv.* 

from ProjectFieldValue pfv

where (pfv.dateValue between '2019-05-01' AND '2019-05-30' AND pfv.fieldKey = 'closing_date') 

OR(pfv.textValue = 'Open' AND pfv.fieldKey = 'contract_status')

此外,我更改了 pfv.textValue = 'Close' 為 pfv.textValue='Open' 因為““contact_status”的 fieldKey 和“Open”的 fieldKey 的 textValue”


然后你會得到滿足的記錄


“contact_status”的 fieldKey 和“Open”的 fieldKey 的 textValue 或

“close_date”的fieldKey和2019-05-01 AND 2019-05-30之間的dateValue

如果只想獲取 1.“contact_status”的 fieldKey 和“Open”的 fieldKey 的 textValue


你可以


select pfv.* 

from ProjectFieldValue pfv

where pfv.textValue = 'Open' AND pfv.fieldKey = 'contract_status'

并只獲取記錄


“close_date”的fieldKey和2019-05-01 AND 2019-05-30之間的dateValue

select pfv.* 

from ProjectFieldValue pfv

where (pfv.dateValue between '2019-05-01' AND '2019-05-30' AND pfv.fieldKey = 'closing_date')



查看完整回答
反對 回復 2021-11-05
?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

我認為您需要將您的選擇拆分為 2 并進行子查詢.... 檢查此文檔:

https://www.w3resource.com/mysql/subqueries/index.php


查看完整回答
反對 回復 2021-11-05
  • 2 回答
  • 0 關注
  • 149 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號