[leetcode]596. Classes More Than 5 Students

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/kangbin825/article/details/74078923

There is a table courses with columns: student and class

Please list out all classes which have more than or equal to 5 students.

For example, the table:

+---------+------------+
| student | class      |
+---------+------------+
| A       | Math       |
| B       | English    |
| C       | Math       |
| D       | Biology    |
| E       | Math       |
| F       | Computer   |
| G       | Math       |
| H       | Math       |
| I       | Math       |
+---------+------------+

Should output:

+---------+
| class   |
+---------+
| Math    |
+---------+

Solution:

# Write your MySQL query statement below
select a.class from (select class,count(class) from (select distinct student,class from courses) as b group by class having count(class)>=5) as a;


展开阅读全文

need more than 1 value to unpack的问题

03-16

最近跟着《父与子的编程之旅》学习python,rn在学习到事件一章时 ,在PyPong中出现了“need more than 1 value to unpack“的问题rn代码如下:rnimport pygame,sysrnrnclass MyPpx(pygame.sprite.Sprite):rn def __init__(self,image_file,speed,location):rn pygame.sprite.Sprite.__init__(self)rn self.image = pygame.image.load(image_file)rn self.speed = speedrn self.rect = self.image.get_rect()rn self.rect.left,self.rect.top = locationrnrn def move():rn global score,score_surf,score_fontrn self.rect = self.rect.move(self.speed)rn if self.rect.left <0 or self.rect.right>screen.get_width():rn speed[0]=-speed[0]rnrn if self.rect.top<=0:rn self.speed[1] = -self.speed[1]rn score +=1rn score_surf = score_font.render(str(score),1,(0,0,0))rnrnclass MyPaddleClass(pygame.sprite.Sprite):rn def __init__(self,location=[0,0]):rn pygame.sprite.Sprite.__init__(self)rn image_surface = pygame.surface.Surface([100,20])rn image_surface.fill([0,0,0])rn self.image = image_surface.convert()rn self.rect = self.image.get_rect()rn[color=#FF0000] self.rect.left,self.rect.top = location[/color] #提示这句“need more than 1 value to unpack”rnpygame.init()rnscreen = pygame.display.set_mode([640,480])rnclock = pygame.time.Clock()rnmyppx = MyPpx("ppx.png",[10,5],[50,50])rnballGroup = pygame.sprite.Group(myppx)rnpaddle = MyPaddleClass([270.400])rnlives = 3rnscore = 0rnrn[color=#FF0000]Traceback (most recent call last):rn File "C:\Python27\Pygame\pypong.py", line 36, in rn paddle = MyPaddleClass([270.400])rn File "C:\Python27\Pygame\pypong.py", line 30, in __init__rn self.rect.top = locationrnValueError: need more than 1 value to unpack[/color]rn请大神帮忙看看 论坛

mysql 返回Result consisted of more than one row

09-03

RTrn 我好像没有返回这记录集,在线请高手指点。小弟不圣感谢,小弟分数不多了。希望高手不要嫌弃,代码很简单,就是从表读45次,每次id不同,然后插入到临时表里。在线等高手。。。。rnbeginrndeclare tatol int(10);rndeclare id int;rndeclare name varchar(20);rndeclare taidu_manyi int(10);rndeclare taidu_yiban int(10);rndeclare taidu_bumanyi int(10);rndeclare huanjin_manyi int(10);rndeclare huanjin_yiban int(10);rndeclare huanjin_bumanyi int(10);rndeclare zhuangkuang_manyi int(10);rndeclare zhuangkuang_yiban int(10);rndeclare zhuangkuang_bumanyi int(10);rndeclare pingjun int(10);rnDROP TABLE IF EXISTS TEMP;rnCREATE TABLE `TEMP` (rn`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,rn`taidu_manyi` INT( 20 ) NOT NULL ,rn`taidu_yiban` INT( 20 ) NOT NULL ,rn`taidu_bumanyi` INT( 20 ) NOT NULL ,rn`huanjin_manyi` INT( 20 ) NOT NULL ,rn`huanjin_yiban` INT( 20 ) NOT NULL ,rn`huanjin_bumanyi` INT( 20 ) NOT NULL ,rn`zhuangkuang_manyi` INT( 20 ) NOT NULL ,rn`zhuangkuang_yiban` INT( 20 ) NOT NULL ,rn`zhuangkuang_bumanyi` INT( 20 ) NOT NULL ,rn`pingjun` INT( 20 ) NOT NULL ,rn`title` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL) ENGINE = MYISAM ;rnselect count(*) into tatol from wxw_myself;rnset id=1;rnwhile id<=45 dornselect (count(*)/tatol)*100 into taidu_manyi from wxw_card where nid=id and service_taidu=10;rnselect (count(*)/tatol)*100 into taidu_yiban from wxw_card where nid=id and service_taidu=8;rnselect (count(*)/tatol)*100 into taidu_bumanyi from wxw_card where nid=id and service_taidu=6;rnselect (count(*)/tatol)*100 into huanjin_manyi from wxw_card where nid=id and service_huanjin=10;rnselect (count(*)/tatol)*100 into huanjin_yiban from wxw_card where nid=id and service_huanjin=8;rnselect (count(*)/tatol)*100 into huanjin_bumanyi from wxw_card where nid=id and service_huanjin=6;rnselect (count(*)/tatol)*100 into zhuangkuang_manyi from wxw_card where nid=id and service_zhuangkuang=10;rnselect (count(*)/tatol)*100 into zhuangkuang_yiban from wxw_card where nid=id and service_zhuangkuang=8;rnselect (count(*)/tatol)*100 into zhuangkuang_bumanyi from wxw_card where nid=id and service_zhuangkuang=6;rnselect title into name from wxw_name;rnselect (sum(service_taidu)+sum(service_huanjin)+sum(service_zhuangkuang))/3/tatol into pingjun from wxw_card where nid=id;rninsert into temp values('',taidu_manyi,taidu_yiban,taidu_bumanyi,huanjin_manyi,huanjin_yiban,huanjin_bumanyi,zhuangkuang_manyi,zhuangkuang_yiban,zhuangkuang_bumanyi);rnset id=id+1;rnend while;rnendrnrn 论坛

请问~~~ora-01207:file is more recent than controlfile - old controlfile??

08-27

请问~~~ora-01207:file is more recent than controlfile - old controlfile?? rn我的数据库rnshutdown后再startup / force 出错:rnora-01122:database file string failed verification checkrnora-01110:datfile string 'd:\oracle\oradata\blzgc\system01.dbf'rnora-01207:file is more recent than controlfile - old controlfilernrnbin2bb说要create new controlfile如下:rnCreate controlfile by yourself rnRun the follow command in svrmgrl:rnsvrmgrl> alter database backup controlfile to trace;rnThen find this trace file and edit it: rn--Create_controlfile.sqlrnSTARTUP NOMOUNTrnCREATE CONTROLFILE SET DATABASE "PROD" RESETLOGS NOARCHIVELOGrnMAXLOGFILES 16rnMAXLOGMEMBERS 2rnMAXDATAFILES 500rnMAXINSTANCES 1rnMAXLOGHISTORY 226rnLOGFILErnGROUP 1 (rn'/u8/orauat/uatdata/log01a.dbf',rn'/u8/orauat/uatdata/log01b.dbf'rn) SIZE 10M,rnGROUP 2 (rn'/u8/orauat/uatdata/log02a.dbf',rn'/u8/orauat/uatdata/log02b.dbf'rn) SIZE 10MrnDATAFILErn'/u6/orauat/uatdata/system01.dbf',rn'/u6/orauat/uatdata/system02.dbf',rn......rn......rn......rn'/u10/orauat/uatdata/xtrd01.dbf',rn'/u6/orauat/uatdata/xtrx01.dbf'rnCHARACTER SET WE8ISO8859P15rn;rnRECOVER DATABASE until cancel using backup controlfilernALTER DATABASE OPEN RESETLOGS;rnALTER TABLESPACE TEMP ADD TEMPFILE '/u6/orauat/uatdata/temp01.dbf' REUSErnrn可是:rn当我运行recover database util cancel using backup controlfile后ora让我指定日志,我的数据库是非归档模式的,三个redo.log都试过,出两种错rn(1):ora-00310:archived log contains sequence string(69456);sequence string(69454) requiredrnora-00334:archived log:'......*.log(my logfile)'rnora-01547:waring:recover succedded but open resetlogs would get error belowrnora-01194:file '......\system01.dbf' needs more recovery to be consistentrn好像看ora doc 上说要先检查Are All Data Files and Redo Logs OK? 大家是怎么检查的?ora doc:“First, look at the data files. Each of the data files probably has the same modification time, or there might be a group of them with one modification time and another group with a different modification time. The main thing to look for is a missing file or a zero length file. Something else to look for is one or more files that have a modification time that is newer than the newest online redo log file. If a data file meets any one of these conditions, it must be restored from backup. ”如果我的datafile比redo.log新,要先recover datafile后才能重建ctlfile,但当我recover tablespace system时就报rnora-00283:rnora-01610:recovery using the backup controlfile option must be donern(2):ora-00283:recovery session canceled due to errorsrnora-00600:internal error code,arguments:[][][].................... rn好像是redo.log损坏了rn我该怎么办?rn 论坛

出现错误:Subquery returns more than 1 row

05-11

这是一个进销存的出入库项目部分,现在问题不知道出在哪里,请各位大虾帮帮忙,帮忙看看rnrn```rn java.sql.SQLException: Subquery returns more than 1 rowrn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)rn at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)rn at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)rn at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)rn at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330)rn at com.sxt.gmms.dao.instorage.InStorageDao.addInStorageAndItem(InStorageDao.java:40)rn at com.sxt.gmms.frame.instorage.instorage.InStorageFrame.actionPerformed(InStorageFrame.java:233)rn at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)rn at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)rn at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)rn at javax.swing.DefaultButtonModel.setPressed(Unknown Source)rn at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)rn at java.awt.Component.processMouseEvent(Unknown Source)rn at javax.swing.JComponent.processMouseEvent(Unknown Source)rn at java.awt.Component.processEvent(Unknown Source)rn at java.awt.Container.processEvent(Unknown Source)rn at java.awt.Component.dispatchEventImpl(Unknown Source)rn at java.awt.Container.dispatchEventImpl(Unknown Source)rn at java.awt.Component.dispatchEvent(Unknown Source)rn at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)rn at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)rn at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)rn at java.awt.Container.dispatchEventImpl(Unknown Source)rn at java.awt.Window.dispatchEventImpl(Unknown Source)rn at java.awt.Component.dispatchEvent(Unknown Source)rn at java.awt.EventQueue.dispatchEventImpl(Unknown Source)rn at java.awt.EventQueue.access$200(Unknown Source)rn at java.awt.EventQueue$3.run(Unknown Source)rn at java.awt.EventQueue$3.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)rn at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)rn at java.awt.EventQueue$4.run(Unknown Source)rn at java.awt.EventQueue$4.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)rn at java.awt.EventQueue.dispatchEvent(Unknown Source)rn at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)rn at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)rn at java.awt.EventDispatchThread.pumpEvents(Unknown Source)rn at java.awt.EventDispatchThread.pumpEvents(Unknown Source)rn at java.awt.EventDispatchThread.run(Unknown Source)rnrnrn这是项目的源代码rn/**rn * 商品入库的DAO层rn * rn * @author Administratorrn * rn */rnpublic class InStorageDao rnrn public void addInStorageAndItem(InStorage inStorage,rn List itemList) rn Connection con = null;rn PreparedStatement stat = null;rn ResultSet rs = null;rn try rn con = DBUtil.getConn();rn // 设置自动提交为falsern con.setAutoCommit(false);rn // 先保存入库单rn String inSql = "insert into iss_in(" + "in_code," + "in_date,"rn + "in_status," + "emp_id)" + " values(?,?,?,("rn + "select emp_id from iss_employee "rn + "where emp_name=?)) ";rn stat = con.prepareStatement(inSql, new String[] "in_id" );rn stat.setString(1, inStorage.getInCode());rn stat.setDate(2, new java.sql.Date(inStorage.getInDate().getTime()));rn stat.setInt(3, inStorage.getInStatus());rn stat.setString(4, inStorage.getEmp().getEmpName());rn stat.executeUpdate();//出错了???rnrn // 取得返回的入库单idrn int inId = 0;rn rs = stat.getGeneratedKeys();rn if (rs.next()) rn inId = rs.getInt(1);rn rn // 再保存入库明细rn String itemSql = "insert into iss_in_item(" + "in_item_price,"rn + "in_item_qty," + "in_item_status," + "goods_id,"rn + "in_id)" + "values(?,?,?,"rn + "(select goods_id from iss_goods where goods_code = ?),"rn + "?)";rn stat = con.prepareStatement(itemSql);rn for (InStorageItem inStorageItem : itemList) rn stat.setFloat(1, inStorageItem.getInItemPrice());rn stat.setInt(2, inStorageItem.getInItemQty());rn stat.setInt(3, 1);rn stat.setString(4, inStorageItem.getGoods().getGoodsCode());rn stat.setInt(5, inId);rn stat.executeUpdate();rn rn con.commit();rn catch (Exception e) rn e.printStackTrace();rn try rn con.rollback();rn catch (SQLException e1) rn e1.printStackTrace();rn rn finally rn DBUtil.closeConn(con, stat, rs);rn rn rnrnrn```rnrnrn 这是数据库部分,用的是MySQL数据库,请各位大虾帮帮忙!rn![图片说明](https://img-ask.csdn.net/upload/201605/11/1462948190_737156.png)rnrn![图片说明](https://img-ask.csdn.net/upload/201605/11/1462948205_833102.png) 问答

依然是Result consisted of more than one row,我要哭了

12-18

错误出现在这段代码里面,这是一个存储过程的片段,这段注释掉就不会错,但我还要这功能呢,求大神解答。rn[code=SQL]rnIF ClassID=-1 THENrn beginrn DECLARE X int;rn DECLARE done int;rn DECLARE t_cursor cursor for SELECT ID From TopWinCMS_Class where ParentID=0 and IsShowInIndex=1 and rnLinkUrl =N'' and `ModelID` = ModelID order by `RootID` limit 1;rn declare continue handler FOR NOT FOUND SET done = 1; rn SET @SQL='';rn SET done = 0;rn open t_cursor;rn while done = 0 dorn beginrn fetch t_cursor into X;rn SET @SQL=concat('select ID,ModelID,ClassID,ClassName,ContentTitle,Hits,'''' as Content,ColorStyle,FontStyle,UpdateTime,TemplateFileName from VW_',TableName,' where deleted=0 and Pass=1 and ClassID in (',Get_ClassIDs(X),') limit ',TOP); rn PREPARE stmt1 FROM @SQL;rn EXECUTE stmt1; rn DEALLOCATE PREPARE stmt1;rn end;rn end while;rn close t_cursor;rn end;rnEND IF;rn[/code]rnrnGet_ClassIDs(X)rn代码如下rn[code=C#]rndelimiter $$rndrop function if exists Get_ClassIDs;rnCREATE FUNCTION Get_ClassIDs(iid int) rnRETURNS VARCHAR(8000)rnBEGINrnDECLARE IDs VARCHAR(255);rnDECLARE PPt VARCHAR(255);rnSelect concat(`Path`,'%') into PPt FROM TopWinCMS_Class where `ID`=iid;rnset @IDs='';rnselect concat(@IDs,`ID`,',') into @IDs from TopWinCMS_Class where Path Like PPt;rnIF LENGTH(@IDs)>0 THENrn set @IDs=left(@IDs,lenth(@IDs)-1);rnELSErn set @IDs='0';rnend if;rnreturn @IDs;rnend$$rn[/code] 论坛

没有更多推荐了,返回首页