SET @EE='';
創(chuàng)新互聯(lián)為客戶提供專業(yè)的網(wǎng)站設(shè)計(jì)、做網(wǎng)站、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁設(shè)計(jì)、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、成都手機(jī)網(wǎng)站制作等網(wǎng)站方面業(yè)務(wù)。
SELECT @EE:=CONCAT(@EE,'SUM(IF(C2=/'',C2,'/'',',C3,0)) AS ',C2,',') FROM (SELECT DISTINCT C2 FROM TX) A;
SET @QQ=CONCAT('SELECT ifnull(c1,\'total\'),',LEFT(@EE,LENGTH(@EE)-1),' ,SUM(C3) AS TOTAL FROM TX GROUP BY C1 WITH ROLLUP');
PREPARE stmt2 FROM @QQ;
EXECUTE stmt2;
這個(gè)好復(fù)雜,你學(xué)的是mysq嗎?
/* 使用方法 直接執(zhí)行 傳入?yún)?shù)(series_guid 查詢條件)返回一個(gè)數(shù)據(jù)集 如 查詢?cè)撓盗蠧ylindrical 下所有產(chǎn)品 dbo P_GetSeriesProductDetail Cylindrical 查詢系列Cylindrical 下含有BK 的產(chǎn)品 dbo P_GetSeriesProductDetail Cylindrical product_name like %BK % */ CREATE PROCEDURE P_GetSeriesProductDetail(@series_guid varchar( ) @condition varchar( )) AS DECLARE @ParamNo nvarchar( ) DECLARE @SQL nvarchar( ) Set @SQL= DECLARE P_cursor CURSOR local fast_forward FOR SELECT param_no FROM V_product_params where series_guid=@series_guid OPEN P_cursor
FETCH next FROM P_cursor INTO @ParamNo WHILE (@@fetch_status = ) BEGIN Set @SQL = @SQL + MAX(CASE param_no WHEN + @ParamNo + THEN param_value ELSE END) AS F + @ParamNo + char( ) FETCH next FROM P_cursor INTO @ParamNo END
CLOSE P_cursor DEALLOCATE P_cursor Set @SQL= SELECT type_guid series_guid product_no product_name + @SQL + FROM V_product_params WHERE series_guid= + @series_guid + if (LTrim(@condition) ) Set @SQL= @SQL + and + @condition Set @SQL= @SQL + GROUP BY type_guid series_guid product_no product_name
lishixinzhi/Article/program/MySQL/201311/29566
\--我寫下我的思路吧--\
--先取工號(hào)姓名,如果考勤表.EMPLOYEEID=員工表.employeeID,則--\
select?b.employeeno?工號(hào),b.name?姓名?from?atten?a,employee?b
where?a.employeeid=b.employeeID?--假設(shè)考勤表是atten--
--------------------------------------
\--行轉(zhuǎn)列,將1號(hào)到30號(hào),從IN_TEIM、OUT_TIME中獲取
select?
if?(IN_TIME?like?'01.11%',RIGHT(IN_TIME,5),null)?as?'1號(hào)上班'
if?(OUT_TIME?like?'01.11%',RIGHT(OUT_TIME,5),null)?as?'1號(hào)下班'
from?ATTEN?group?by?IN_TIME,OUT_TIME
--如何實(shí)現(xiàn)將多個(gè)數(shù)值寫到一個(gè)字段中,還需要再研究下。大體思路就這這樣。--\