查询以显示字段 [英] Query to display the fields

查看:81
本文介绍了查询以显示字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我试图选择一条具有所有不同值的记录.我的问题如下:

1.首先,我想显示特定月份的预定日期列表.
2.然后在该特定月份,我要显示该特定日期举行的事件.
3.现在,我想在一个查询中基于两个数据显示所有详细信息,并显示两个以上条件计数"

注意:与EventDates无关,应该只有不同的值,并且没有重复的行/列值


预期输出为:

Hello,


I am trying to select a record which has all the distinct values. My question as follows:

1. Firstly I want to display the list of dates scheduled in particular month(s).
2. Then in that particular month i want to display down the events held in the particular date.
3. Now I want to display all the details based on both the data in a single query with the "above two condition counts"

Note: There should be only distinct values and not any repeating row/column values another irrespective of EventDates


The Expected Output is :

eventid	#ofparticipants	   EventName	          EventDate
101	   15		             Event1               [31/10/2011]
115	   11		             Event2               [02/11/2011]
114	   11		             Event3               [03/11/2011]





-这是我的第一个查询:

选择EventDate,count(distinct EventCode)作为[TotalEvents]
来自Tt_Events的a.EventId = b.EventId上的联接Mt_EventsSchedule b
其中EventDate!=''''
按EventDate分组
通过EventDate订购


-这是我的第二个查询:


选择不同的b.EventCode作为Paper,选择count(a.EventAppId)作为EvntId,b.EventName
从Tt_StudentAppliForm_Details联接a.EventId = b.EventId上的EventsSchedule b
在a.EventAppId = c.EventAppId上加入Tt_StudentAppliForm_Basic c

按EventCode分组,EventName
由EvntId desc
订购


现在,我想合并两个查询并获得上面的输出.

请帮忙... !!!!

谢谢





--This is my first query:

select EventDate,count(distinct EventCode) as [TotalEvents]
from Tt_Events a join Mt_EventsSchedule b on a.EventId = b.EventId
where EventDate != ''''
group by EventDate
order by EventDate


--This is my second query:


select distinct b.EventCode as Paper,count(a.EventAppId) as EvntId ,b.EventName
from Tt_StudentAppliForm_Details a join EventsSchedule b on a.EventId = b.EventId
join Tt_StudentAppliForm_Basic c on a.EventAppId= c.EventAppId

group by EventCode ,EventName
order by EvntId desc



Now I want to merge the two queries and get the above output.

Please Help...!!!!

Thank You

推荐答案

以下是一些概念的提示,可帮助您自己编写查询.

MONTH(Transact-SQL)

SQL SELECT DISTINCT语句

UNION(Transact-SQL)
Here are some Hints around some concepts which will help you to write your queries by your own.

MONTH (Transact-SQL)

SQL SELECT DISTINCT Statement

UNION (Transact-SQL)


您不没有提供任何表数据,因此不清楚输出来自何处.但是...我尝试一下.

您提到要获取不同的记录,因此首先要注意.重要的是要知道,distinct实际上是简化的分组依据".考虑到这一点,您可以轻松地按自己喜欢的方式对记录进行分组.

You don''t supply any table data so it isn''t clear where the output came from But... I give it a try.

You mention you want distinct records so first about that. It is important to know that distinct is actually a simplified "group by". With this in mind you can easily group the records in the way you like.

SELECT eventid, ofparticipants, EventName, EventDate 
   FROM Events
   WHERE EventDate IN (date1, date2, ...)
   GROUP BY eventid, EventDate;



请记住,通过在group by中首先使用eventid,您只会获得带有该eventid的一条记录.但是,如果eventid是该表的主要索引,则可以将其省略,因为它将始终是一个不同的值.

希望这可以帮助您,否则您可以添加一些额外的信息(例如一些表记录和您期望的输出)

祝你好运!



Keep in mind that by using eventid first in the group by, you only will get one record with that eventid. But if eventid is the primary index of this table you can leave it out because it will always be a distinct value.

Hopefully this will get you going and otherwise you might add some extra info (like some table records and the output you expect)

Good luck!


这篇关于查询以显示字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆