distinct

query to return a single row with the multiple items in separate columns within the row

浪尽此生 提交于 2020-02-05 01:51:26
问题 I have a situation where I return results with multiple rows. I'm looking for a way to return a single row, with the multiple items in separate columns within the row. My initial query: SELECT a.name, a.city, a.address, a.abbrv, b.urltype, b.url FROM jos__universityTBL as a LEFT JOIN jos__university_urlTBL as b on b.universityID = a.ID WHERE a.stateVAL = 'CA' My output: | University Of Southern Califor | Los Angeles | | usc | 2 | http://web-app.usc.edu/ws/soc/api/ | | University Of Southern

SQL经典50题

纵饮孤独 提交于 2020-02-04 16:06:25
用到的表的介绍 student: sid(学生ID),sname(学生姓名),sage,ssex course: cid(课程ID),cname,tid(教师ID) teacher: tid,tname sc:sid,cid,score 只是附上题目和代码,没有运行结果 1.查询"01"课程比"02"课程成绩高的学生的信息及课程分数 select * from (select t1.sid,class1,class2 from (select sid,score as class1 from sc where cid='01' )as t1 join (select sid,score as class2 from sc where cid='02') as t2 on t1.sid=t2.sid and t1.class1>t2.class2 )r left join student on r.sid=student.sid ; 1.1 查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null ) select * from (select * from sc where cid='01')t1 left join (select * from sc where cid='02')t2 on t1.sid=t2.sid ; 1.2

Select Distinct on Inner Join Query filtering by multiple values on a single column?

被刻印的时光 ゝ 提交于 2020-02-03 05:45:30
问题 So, i have to say, SQL is by far my weakest side as a developer. Perhaps what i'm trying to accomplish is pretty easy. I have something like this (It's not the real model, but in order to make it simple to understand without wasting too much time explaining it, i've come up with an example that mimics exactly the table relations i have to use). On one hand, a table, let's call it, "Users". Columns such as a primary key "UserId", "UserName", and so on. Next, another Table, "Licenses". Relates

How to fetch distinct values with arel/relational algebra and has_many :through

安稳与你 提交于 2020-02-02 07:22:52
问题 When I try to display all movies that a person is in, and they have more than 1 role (director,writer,actor) in a movie, I get multiple lines for that movie. If I add .select('DISTINCT id') or movies.* to try and eliminate the dups I get the following error: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT id FROM movies INNER JOIN movie_people ON movies .id = movie_peop' at line 1:

How to fetch distinct values with arel/relational algebra and has_many :through

孤街醉人 提交于 2020-02-02 07:22:15
问题 When I try to display all movies that a person is in, and they have more than 1 role (director,writer,actor) in a movie, I get multiple lines for that movie. If I add .select('DISTINCT id') or movies.* to try and eliminate the dups I get the following error: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT id FROM movies INNER JOIN movie_people ON movies .id = movie_peop' at line 1:

Mysql进阶查询

女生的网名这么多〃 提交于 2020-02-01 07:09:03
MySQL中CONCAT()的用法 mysql concat(str1,str2,…) ,可以拼接多个函数 SELECT CONCAT ( '四川省' , '-' , '成都' , '-' , '武侯区' ) AS 收货地址 执行结果为:四川省-成都-武侯区 值得注意的是:如果存在参数为null,则结果直接为null 处理方式: SELECT 列名1,列名2,列名3,…,列名n,IFNULL(‘列名’,0) AS ‘别名’ FROM ‘表名’ SELECT id , email , gender , last_name , IFNULL ( age , 0 ) AS age FROM `employee` DISTINCT 语句 在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。 关键词 DISTINCT 用于返回唯一不同的值。 语法: SELECT DISTINCT 列名称 FROM 表名称 需求:查询年龄不等于18岁的员工信息; SELECT * FROM employee WHERE age <> 18 <> 和 != 是等价的,但是推荐使用<> && || ! and or not 上下是相对的,在Mysql中推荐使用and、or、not 作为连接; #转换成大写 SELECT UPPER ( "abc" ) ; #转换成小写

How to filter duplicate values emitted by observable in RXJava?

ぃ、小莉子 提交于 2020-01-31 22:09:11
问题 I have a collection of objects, where i want to suppress duplicate items. I know about Distinct operator, but if i am not mistaken it compare items by properly overrided hashcode method. But what if my hashcode returns different values for same objects, and i want to set equality by my own. distinct have 2 overloaded methods - one without params and one with Func1 param,i suppose that i should use 2nd method, but how exaclty? .distinct(new Func1<ActivityManager.RunningServiceInfo, Object>() {

How to filter duplicate values emitted by observable in RXJava?

拟墨画扇 提交于 2020-01-31 22:05:43
问题 I have a collection of objects, where i want to suppress duplicate items. I know about Distinct operator, but if i am not mistaken it compare items by properly overrided hashcode method. But what if my hashcode returns different values for same objects, and i want to set equality by my own. distinct have 2 overloaded methods - one without params and one with Func1 param,i suppose that i should use 2nd method, but how exaclty? .distinct(new Func1<ActivityManager.RunningServiceInfo, Object>() {

Access Query Memo field truncation due to “distinct”

大城市里の小女人 提交于 2020-01-30 08:42:30
问题 I am having problems running a query without either truncating the note field in NotesTbl or returning repeated entries. UID is not unique for AccessTbl. When I leave out "distinct" notes will return multiple times because I am joining with AccessTbl on a non-distinct condition. When I use distict, the note field is trunctated because it is a memo field. Here is my query: SELECT DISTINCT NotesTbl.pin, NotesTbl.noteid, NotesTbl.note, NotesTbl.date, AccessTbl.affiliation, AccessTbl.name FROM

Want to remove duplicated rows unless NA value exists in columns

家住魔仙堡 提交于 2020-01-30 08:38:33
问题 I have a data table with 4 columns: ID, Name, Rate1, Rate2. I want to remove duplicates where ID, Rate1, and Rate 2 are the same, but if they are both NA, I would like to keep both rows. Basically, I want to conditionally remove duplicates, but only if the conditions != NA. For example, I would like this: ID Name Rate1 Rate2 1 Xyz 1 2 1 Abc 1 2 2 Def NA NA 2 Lmn NA NA 3 Hij 3 5 3 Qrs 3 7 to become this: ID Name Rate1 Rate2 1 Xyz 1 2 2 Def NA NA 2 Lmn NA NA 3 Hij 3 5 3 Qrs 3 7 Thanks in