-4
告訴我查詢是否正確,或包含任何錯誤:如何確定SQL語句是否會運行?
select cname from company where id IN (
select company_id,count(*) from medication
group by(company_id) having count(*)>1
)
order by cname;
告訴我查詢是否正確,或包含任何錯誤:如何確定SQL語句是否會運行?
select cname from company where id IN (
select company_id,count(*) from medication
group by(company_id) having count(*)>1
)
order by cname;
供您參考。您可以隨時在MySQl/PHPMyadmin上運行您的查詢,以便顯示您的錯誤。
另外,您可以使用以下工具
https://www.piliapp.com/mysql-syntax-check/
我希望它能幫助
包含你不能在(選擇COMPANY_ID,計數() 錯誤刪除計數()可能適合您,請檢查以下
個/*
create table company(id int,cname varchar(10));
insert into company values
(1,'abc'),(2,'def'),(3,'ghi');
create table medication(id int,company_id int);
truncate table medication;
insert into medication values
(1,1),
(2,1),
(3,1),
(4,2),
(5,2),
(6,2),
(7,3),
(8,2);
*/
這個代碼
select cname from company
where id IN (select company_id from medication group by(company_id) having count(*) > 1)
order by cname;
結果
+-------+
| cname |
+-------+
| abc |
| def |
+-------+
它是否運行?你有沒有得到任何錯誤? – tadman
取決於表結構和預期的結果,查詢將產生 –