string sql_phy250 = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =250 ";
string sql_phy500 = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =500 ";
string sql_phy750 = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =750 ";
string sql_phy1000 = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =1000 ";
从数据表user_status里面分别查询status等于250 500 750 1000的记录条数!
能合并成一条语句嘛?
这样要执行4次数据库查询好痛苦。
SQL高手指点下!!!谢谢!
string sql_phy_ALL = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and (status =250 or status =500 or status =750 or status =1000 )";
string sql_phy250 = "select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status in (250,500,750,1000) ";--按照status分别查?
string sql_phy250 = "select status , count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status in (250,500,750,1000) group by status";
string sql_phy250 = "select status , count(*)
from user_status
where userID=(select userID from user_base where username ='" + name + "')
and year='" + year + "' and month='" + month + "'
and status in (250,500,750,1000) group by status";
[/SQL]
from user_status
where userID=(select userID from user_base where username ='" + name + "')
and year='" + year + "' and month='" + month + "'
//1种方法 and status in (250,500,750,1000)";//2种方法 and (status =250 or status =500 or status =750 or status =1000 )";
还有UNION ALL
union all
select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =500
union all
select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =750
union all
select count(*) from user_status where userID=(select userID from user_base where username ='" + name + "') and year='" + year + "' and month='" + month + "' and status =1000 "