select
我們提供的服務(wù)有:網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、高陽ssl等。為上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的高陽網(wǎng)站制作公司
goods_name?產(chǎn)品名字,
max(price)?價格,
max(case?rank_name?when?'VIP1'?then?(case?when?user_price?is?null?then?discount*price/100?else?user_price?end)?end)?vip1價格,
max(case?rank_name?when?'VIP2'?then?(case?when?user_price?is?null?then?discount*price/100?else?user_price?end)?end)?vip2價格,
max(case?rank_name?when?'VIP3'?then?(case?when?user_price?is?null?then?discount*price/100?else?user_price?end)?end)?vip3價格
from?member_price?mp
left?join?goods?gd?on?gd.goods_id?=?mp.goods_id
left?join?user_rank?ur?on?ur.rank_id?=?mp.rank_id
group?by?goods_name;
mysql不是很熟悉,所以寫了個標(biāo)準sql語法的。我記得mysql中g(shù)roup by的select可以不用跟聚合函數(shù)的,所以LZ大概可以把max()去掉,而mysql中好像有isnull,ifnull的函數(shù),我不太了解,這里用case語句替代了,LZ可以自行替換。
這個是SQL SERVER的語法,MY SQL的思路應(yīng)該是類似的
---------------------------------------------------------
select
*
from
(select
isnull(sum(online_count),0) h16
from
#a
where
datepart(hh,watch_time)=16) a,
(select
isnull(sum(online_count),0) h17
from
#a
where
datepart(hh,watch_time)=17) b,
(select
isnull(sum(online_count),0) h18
from
#a
where
datepart(hh,watch_time)=18) c,
(select
isnull(sum(online_count),0) h19
from
#a
where
datepart(hh,watch_time)=19) d
最好是拆開來使用,比如數(shù)據(jù)里面有1,2,3 你要查詢 1,3
就寫find_in_set('1',ids) and find_in_set('2',ids);
如果你只是查詢2
就直接 where find_in_set('2',ids);
如果是完全要相等 就直接寫等于啊,如果只是需要包含就用上面的、