Tuesday, March 27, 2012
Create a Table using another table!
Sorry to trouble you all, but I am not getting anywhere!
I need to copy the contents of 1 table into a new temporary table. What I am
doing is :
SELECT *
FROM U_regulargiver
WHERE Status ='I'
OR Status ='N'
INTO TABLE #U_T_Committed
Obviously I'm doing something wrong, but I can't seem to figure out exactly
what. Can anyone please help?
Thanks in advance
RobYou screwed up with the syntax:
> SELECT *
> INTO TABLE #U_T_Committed
> FROM U_regulargiver
> WHERE Status ='I'
> OR Status ='N'
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Robert" <Robert@.discussions.microsoft.com> schrieb im Newsbeitrag
news:7BE6CA67-EF93-4A97-8BA7-22220C06E0FA@.microsoft.com...
> Hi,
> Sorry to trouble you all, but I am not getting anywhere!
> I need to copy the contents of 1 table into a new temporary table. What I
> am
> doing is :
> SELECT *
> FROM U_regulargiver
> WHERE Status ='I'
> OR Status ='N'
> INTO TABLE #U_T_Committed
> Obviously I'm doing something wrong, but I can't seem to figure out
> exactly
> what. Can anyone please help?
> Thanks in advance
> Rob
>|||You can get the results you want by writing the statement this way.
Create Table #temp
(
Test nvarchar (10),
Description nvarchar (255)
)
select * from testuser.dbo.MyTable
Insert into #temp
Select *
from testuser.dbo.MyTable
Select * from #temp
Drop table #temp
refer to Books Online for more information if you must use the INTO clause.
"Robert" wrote:
> Hi,
> Sorry to trouble you all, but I am not getting anywhere!
> I need to copy the contents of 1 table into a new temporary table. What I
am
> doing is :
> SELECT *
> FROM U_regulargiver
> WHERE Status ='I'
> OR Status ='N'
> INTO TABLE #U_T_Committed
> Obviously I'm doing something wrong, but I can't seem to figure out exactl
y
> what. Can anyone please help?
> Thanks in advance
> Rob
>
Monday, March 19, 2012
crashing DTS on table import
I am having some trouble importing certain tables from an odbc database
(Sage Line 50). Most of the tables import without any trouble whatsoever,
however there are 2 tables (SOP_items and POP_items) that always crash dts
when it tries to import them. The DTS screen simply dissappears from the
screen with no error. I realise that it is beyond the scope of this
newsgroup to ask about the specific odbc database. However I was wondering
is there a log somewhere which might help me to shed light on what in the
tables is making it crash. To note I can import and link to the tables in
access with no trouble whatsoever. Thanks for your time.
Dan
There will be no DTS log because it sounds as though something is crashing
DTS. Have you looked in Event Viewer?
Have you tried SPing (What SP are you running?)?
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
> Hi
> I am having some trouble importing certain tables from an odbc database
> (Sage Line 50). Most of the tables import without any trouble whatsoever,
> however there are 2 tables (SOP_items and POP_items) that always crash dts
> when it tries to import them. The DTS screen simply dissappears from the
> screen with no error. I realise that it is beyond the scope of this
> newsgroup to ask about the specific odbc database. However I was
> wondering
> is there a log somewhere which might help me to shed light on what in the
> tables is making it crash. To note I can import and link to the tables in
> access with no trouble whatsoever. Thanks for your time.
> Dan
>
|||Thanks,
It has SP3 on it, just looking at the mdac 2.7 sp1, see if this sorts it.
Dan
"Allan Mitchell" <allan@.no-spam.sqldts.com> wrote in message
news:eVWcPREwEHA.2568@.TK2MSFTNGP11.phx.gbl...[vbcol=seagreen]
> There will be no DTS log because it sounds as though something is crashing
> DTS. Have you looked in Event Viewer?
> Have you tried SPing (What SP are you running?)?
> --
> --
> Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
> www.SQLDTS.com - The site for all your DTS needs.
> www.konesans.com - Consultancy from the people who know
>
> "IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
> news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
whatsoever,[vbcol=seagreen]
dts[vbcol=seagreen]
the[vbcol=seagreen]
the[vbcol=seagreen]
in
>
|||Change of plan, going to install Microsoft Data Access Components (MDAC)
2.8, didn't see the newer version at first. I already have SP3 of SQL, it
does advise that SP3a is only for versions below SP3, and as such I
shouldn't install it? Looked in the event log to see if there is any log of
an error, but there is nothing whatsoever. Thanks.
Dan
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
> Hi
> I am having some trouble importing certain tables from an odbc database
> (Sage Line 50). Most of the tables import without any trouble whatsoever,
> however there are 2 tables (SOP_items and POP_items) that always crash dts
> when it tries to import them. The DTS screen simply dissappears from the
> screen with no error. I realise that it is beyond the scope of this
> newsgroup to ask about the specific odbc database. However I was
wondering
> is there a log somewhere which might help me to shed light on what in the
> tables is making it crash. To note I can import and link to the tables in
> access with no trouble whatsoever. Thanks for your time.
> Dan
>
|||MDAC 2.8 doesn't seem to have made any difference. Any ideas?
Thanks
Dan
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:e6wXQ2LwEHA.1296@.TK2MSFTNGP10.phx.gbl...
> Change of plan, going to install Microsoft Data Access Components (MDAC)
> 2.8, didn't see the newer version at first. I already have SP3 of SQL, it
> does advise that SP3a is only for versions below SP3, and as such I
> shouldn't install it? Looked in the event log to see if there is any log
of[vbcol=seagreen]
> an error, but there is nothing whatsoever. Thanks.
> Dan
> "IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
> news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
whatsoever,[vbcol=seagreen]
dts[vbcol=seagreen]
the[vbcol=seagreen]
> wondering
the[vbcol=seagreen]
in
>
|||Since this is an ODBC data source, you can try to turn on
ODBC tracing on the box where the package runs. Make sure to
turn the trace off after you have crashed with tracing
turned on. You can then go through the tracing log file and
look for ODBC errors.
-Sue
On Tue, 2 Nov 2004 09:34:59 -0000, "IT Dep"
<it@.isslimREMOVE_TO_REPLYited.co.uk> wrote:
>MDAC 2.8 doesn't seem to have made any difference. Any ideas?
>Thanks
>Dan
>"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
>news:e6wXQ2LwEHA.1296@.TK2MSFTNGP10.phx.gbl...
>of
>whatsoever,
>dts
>the
>the
>in
>
|||Hi
Thanks for the responses, I think that I have worked out where the problem
was occuring. There were date columns in those two tables which were
causing the crash. The dates were in the form dd/mm/yyyy as well as
mm/dd/yyyy, so no wonder it had trouble with the data - what a wonderful
accounting package, if only it used SQL as the native database! Thanks for
all of your help
Dan
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:gu1fo0h2h1n4j4f3pnkgh8u2lfvl3h3tth@.4ax.com... [vbcol=seagreen]
> Since this is an ODBC data source, you can try to turn on
> ODBC tracing on the box where the package runs. Make sure to
> turn the trace off after you have crashed with tracing
> turned on. You can then go through the tracing log file and
> look for ODBC errors.
> -Sue
> On Tue, 2 Nov 2004 09:34:59 -0000, "IT Dep"
> <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote:
(MDAC)[vbcol=seagreen]
it[vbcol=seagreen]
log[vbcol=seagreen]
database[vbcol=seagreen]
crash[vbcol=seagreen]
tables
>
crashing DTS on table import
I am having some trouble importing certain tables from an odbc database
(Sage Line 50). Most of the tables import without any trouble whatsoever,
however there are 2 tables (SOP_items and POP_items) that always crash dts
when it tries to import them. The DTS screen simply dissappears from the
screen with no error. I realise that it is beyond the scope of this
newsgroup to ask about the specific odbc database. However I was wondering
is there a log somewhere which might help me to shed light on what in the
tables is making it crash. To note I can import and link to the tables in
access with no trouble whatsoever. Thanks for your time.
DanThere will be no DTS log because it sounds as though something is crashing
DTS. Have you looked in Event Viewer?
Have you tried SPing (What SP are you running?)?
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
> Hi
> I am having some trouble importing certain tables from an odbc database
> (Sage Line 50). Most of the tables import without any trouble whatsoever,
> however there are 2 tables (SOP_items and POP_items) that always crash dts
> when it tries to import them. The DTS screen simply dissappears from the
> screen with no error. I realise that it is beyond the scope of this
> newsgroup to ask about the specific odbc database. However I was
> wondering
> is there a log somewhere which might help me to shed light on what in the
> tables is making it crash. To note I can import and link to the tables in
> access with no trouble whatsoever. Thanks for your time.
> Dan
>|||Thanks,
It has SP3 on it, just looking at the mdac 2.7 sp1, see if this sorts it.
Dan
"Allan Mitchell" <allan@.no-spam.sqldts.com> wrote in message
news:eVWcPREwEHA.2568@.TK2MSFTNGP11.phx.gbl...
> There will be no DTS log because it sounds as though something is crashing
> DTS. Have you looked in Event Viewer?
> Have you tried SPing (What SP are you running?)?
> --
> --
> Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
> www.SQLDTS.com - The site for all your DTS needs.
> www.konesans.com - Consultancy from the people who know
>
> "IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
> news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
whatsoever,[vbcol=seagreen]
dts[vbcol=seagreen]
the[vbcol=seagreen]
the[vbcol=seagreen]
in[vbcol=seagreen]
>|||Change of plan, going to install Microsoft Data Access Components (MDAC)
2.8, didn't see the newer version at first. I already have SP3 of SQL, it
does advise that SP3a is only for versions below SP3, and as such I
shouldn't install it? Looked in the event log to see if there is any log of
an error, but there is nothing whatsoever. Thanks.
Dan
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
> Hi
> I am having some trouble importing certain tables from an odbc database
> (Sage Line 50). Most of the tables import without any trouble whatsoever,
> however there are 2 tables (SOP_items and POP_items) that always crash dts
> when it tries to import them. The DTS screen simply dissappears from the
> screen with no error. I realise that it is beyond the scope of this
> newsgroup to ask about the specific odbc database. However I was
wondering
> is there a log somewhere which might help me to shed light on what in the
> tables is making it crash. To note I can import and link to the tables in
> access with no trouble whatsoever. Thanks for your time.
> Dan
>|||MDAC 2.8 doesn't seem to have made any difference. Any ideas?
Thanks
Dan
"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
news:e6wXQ2LwEHA.1296@.TK2MSFTNGP10.phx.gbl...
> Change of plan, going to install Microsoft Data Access Components (MDAC)
> 2.8, didn't see the newer version at first. I already have SP3 of SQL, it
> does advise that SP3a is only for versions below SP3, and as such I
> shouldn't install it? Looked in the event log to see if there is any log
of
> an error, but there is nothing whatsoever. Thanks.
> Dan
> "IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
> news:OgXbKTBwEHA.3976@.TK2MSFTNGP09.phx.gbl...
whatsoever,[vbcol=seagreen]
dts[vbcol=seagreen]
the[vbcol=seagreen]
> wondering
the[vbcol=seagreen]
in[vbcol=seagreen]
>|||Since this is an ODBC data source, you can try to turn on
ODBC tracing on the box where the package runs. Make sure to
turn the trace off after you have crashed with tracing
turned on. You can then go through the tracing log file and
look for ODBC errors.
-Sue
On Tue, 2 Nov 2004 09:34:59 -0000, "IT Dep"
<it@.isslimREMOVE_TO_REPLYited.co.uk> wrote:
>MDAC 2.8 doesn't seem to have made any difference. Any ideas?
>Thanks
>Dan
>"IT Dep" <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote in message
>news:e6wXQ2LwEHA.1296@.TK2MSFTNGP10.phx.gbl...
>of
>whatsoever,
>dts
>the
>the
>in
>|||Hi
Thanks for the responses, I think that I have worked out where the problem
was occuring. There were date columns in those two tables which were
causing the crash. The dates were in the form dd/mm/yyyy as well as
mm/dd/yyyy, so no wonder it had trouble with the data - what a wonderful
accounting package, if only it used SQL as the native database! Thanks for
all of your help
Dan
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:gu1fo0h2h1n4j4f3pnkgh8u2lfvl3h3tth@.
4ax.com...
> Since this is an ODBC data source, you can try to turn on
> ODBC tracing on the box where the package runs. Make sure to
> turn the trace off after you have crashed with tracing
> turned on. You can then go through the tracing log file and
> look for ODBC errors.
> -Sue
> On Tue, 2 Nov 2004 09:34:59 -0000, "IT Dep"
> <it@.isslimREMOVE_TO_REPLYited.co.uk> wrote:
>
(MDAC)[vbcol=seagreen]
it[vbcol=seagreen]
log[vbcol=seagreen]
database[vbcol=seagreen]
crash[vbcol=seagreen]
tables[vbcol=seagreen]
>
Sunday, February 19, 2012
counting when expressions is met
different datset within a table. Firstly is this possible. In other words
table is based on dataset a but i want to have a colum that counts a field in
dataset b based on criteria. (ie field = 174). ThanksJust try this:
=Sum( iif(Fields!SomeFieldNameFromDatasetB.Value = 174, 1, 0), "b")
Note: If your condition is more complex and based on the current value of a
field in dataset A, then you have to work with subreports and pass the field
value from dataset A as parameter to the subreport.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tango" <Tango@.discussions.microsoft.com> wrote in message
news:6AA0A8A4-17EC-40E0-92FC-1E91D3932219@.microsoft.com...
> Am having trouble getting an expression to work that performs a count on a
> different datset within a table. Firstly is this possible. In other words
> table is based on dataset a but i want to have a colum that counts a field
in
> dataset b based on criteria. (ie field = 174). Thanks|||thanks robert ill try it in a sec, what does the lower case 'b" do.
"Robert Bruckner [MSFT]" wrote:
> Just try this:
> =Sum( iif(Fields!SomeFieldNameFromDatasetB.Value = 174, 1, 0), "b")
> Note: If your condition is more complex and based on the current value of a
> field in dataset A, then you have to work with subreports and pass the field
> value from dataset A as parameter to the subreport.
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Tango" <Tango@.discussions.microsoft.com> wrote in message
> news:6AA0A8A4-17EC-40E0-92FC-1E91D3932219@.microsoft.com...
> > Am having trouble getting an expression to work that performs a count on a
> > different datset within a table. Firstly is this possible. In other words
> > table is based on dataset a but i want to have a colum that counts a field
> in
> > dataset b based on criteria. (ie field = 174). Thanks
>
>|||The lower-case b is the name of the second data set (which represents the
scope for the aggregate function). Every aggregate function has an optional
scope parameter.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tango" <Tango@.discussions.microsoft.com> wrote in message
news:4D0E11A9-ED32-4703-8131-CFC61B671BC0@.microsoft.com...
> thanks robert ill try it in a sec, what does the lower case 'b" do.
> "Robert Bruckner [MSFT]" wrote:
> > Just try this:
> > =Sum( iif(Fields!SomeFieldNameFromDatasetB.Value = 174, 1, 0), "b")
> >
> > Note: If your condition is more complex and based on the current value
of a
> > field in dataset A, then you have to work with subreports and pass the
field
> > value from dataset A as parameter to the subreport.
> >
> > --
> > This posting is provided "AS IS" with no warranties, and confers no
rights.
> >
> >
> > "Tango" <Tango@.discussions.microsoft.com> wrote in message
> > news:6AA0A8A4-17EC-40E0-92FC-1E91D3932219@.microsoft.com...
> > > Am having trouble getting an expression to work that performs a count
on a
> > > different datset within a table. Firstly is this possible. In other
words
> > > table is based on dataset a but i want to have a colum that counts a
field
> > in
> > > dataset b based on criteria. (ie field = 174). Thanks
> >
> >
> >
Friday, February 17, 2012
Counting Occurences
has posted exactly the problem.
The table below tracks site traffic across a network. There is 1 row
per pageview and UUID is that user's unique cookie.
CREATE TABLE [dbo].[Stats_Working] (
[inac_stats_id] [int] NOT NULL ,
[hit_time] [datetime] NULL ,
[site_id] [int] NULL ,
[site_cat_id] [int] NULL ,
[item_id] [int] NULL ,
[local_content_cat_id] [int] NULL ,
[UUID] [float] NULL ,
[USER_AGENT] [char] (50) NULL
) ON [PRIMARY]
GO
A client asked: of these pageviews and within each category, how many
are accounted for by users that generated 2 or fewer pageviews, 3+
pageviews, and 4+ pageviews?
I said, "yes, we have that information". I know it's here, but I'm
braindead from looking at what should be a simple solution.
Thanks for any help
Cam Bevis
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Cam Bevis (anonymous@.devdex.com) writes:
> I'm having trouble getting my head around this, and no one in the groups
> has posted exactly the problem.
> The table below tracks site traffic across a network. There is 1 row
> per pageview and UUID is that user's unique cookie.
> CREATE TABLE [dbo].[Stats_Working] (
> [inac_stats_id] [int] NOT NULL ,
> [hit_time] [datetime] NULL ,
> [site_id] [int] NULL ,
> [site_cat_id] [int] NULL ,
> [item_id] [int] NULL ,
> [local_content_cat_id] [int] NULL ,
> [UUID] [float] NULL ,
> [USER_AGENT] [char] (50) NULL
> ) ON [PRIMARY]
> GO
> A client asked: of these pageviews and within each category, how many
> are accounted for by users that generated 2 or fewer pageviews, 3+
> pageviews, and 4+ pageviews?
> I said, "yes, we have that information". I know it's here, but I'm
> braindead from looking at what should be a simple solution.
If I understand this right, and am not too confused at this late hour:
SELECT COUNT(*), no_of_views
FROM (SELECT no_of_views = CASE WHEN cnt <= 2 THEN '<= 2 pagewiews'
WHEN cnt = 3 THEN '= 3 pageviews'
ELSE '>= 4 pageviews'
END
FROM (SELECT cnt, COUNT(*)
FROM Stats_Working
GROUP BY UUID) AS a) AS b
GROUP BY no_of_views
So I am cheating a bit. You don't get 3+ pageviews, but 3 exactly.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks, but not exactly.
What we're trying to return something more like
(pivot this into columns, no room on this editor)
Total Pageviews: 100,000
Pageviews by users that generated 2 or less pageviews:60,000
Pageviews by users that generated 3 or more pageviews:40,000
Pageviews by users that generated 3 or more pageviews:20,000
The trick is counting the occurences of the UUID (unique cookie) in the
table and... select count [distinct?[(uuid)...where count
[distinct?](uuid)<=2,...
something like. I know it's there somewhere.
I guess the goal is best stated as seeing how many pageviews are
generated by people that poke around for a while(or not), and putting
them into groups. It's some kind of metric.
Thanks for your response!
Cam
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Cam Bevis (anonymous@.devdex.com) writes:
> Thanks, but not exactly.
> What we're trying to return something more like
> (pivot this into columns, no room on this editor)
> Total Pageviews: 100,000
> Pageviews by users that generated 2 or less pageviews:60,000
> Pageviews by users that generated 3 or more pageviews:40,000
> Pageviews by users that generated 3 or more pageviews:20,000
>
> The trick is counting the occurences of the UUID (unique cookie) in the
> table and... select count [distinct?[(uuid)...where count
> [distinct?](uuid)<=2,...
> something like. I know it's there somewhere.
It would help if you could provide sample data in form of INSERT statements
and the then desired output from that sample output. That would make it
easier for anyone who tries it to test a solution.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"Cam Bevis" wrote:
> I'm having trouble getting my head around this, and no one in the groups
> has posted exactly the problem.
> The table below tracks site traffic across a network. There is 1 row
> per pageview and UUID is that user's unique cookie.
> CREATE TABLE [dbo].[Stats_Working] (
> [inac_stats_id] [int] NOT NULL ,
> [hit_time] [datetime] NULL ,
> [site_id] [int] NULL ,
> [site_cat_id] [int] NULL ,
> [item_id] [int] NULL ,
> [local_content_cat_id] [int] NULL ,
> [UUID] [float] NULL ,
> [USER_AGENT] [char] (50) NULL
> ) ON [PRIMARY]
> GO
> A client asked: of these pageviews and within each category, how many
> are accounted for by users that generated 2 or fewer pageviews, 3+
> pageviews, and 4+ pageviews?
> I said, "yes, we have that information". I know it's here, but I'm
> braindead from looking at what should be a simple solution.
I ignored the "within each category" requirement above, but this should get
you going:
CREATE TABLE [dbo].[Stats_Working] (
[inac_stats_id] [int] NOT NULL ,
[hit_time] [datetime] NULL ,
[site_id] [int] NULL ,
[site_cat_id] [int] NULL ,
[item_id] [int] NULL ,
[local_content_cat_id] [int] NULL ,
[UUID] [float] NULL ,
[USER_AGENT] [char] (50) NULL
) ON [PRIMARY]
GO
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 1.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 2.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 2.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 3.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 3.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 3.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 4.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 4.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 4.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 4.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 5.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 5.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 5.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 5.0, '')
insert [Stats_Working] values (0, null, 0, 0, 0, 0, 5.0, '')
select UUID, count(*) as 'hits'
from Stats_working
group by UUID
select sum(case when sub.hits <= 2 then sub.hits else 0 end) '2 or fewer',
sum(case when sub.hits >= 3 then sub.hits else 0 end) '3 or more',
sum(case when sub.hits >= 4 then sub.hits else 0 end) '4 or more'
from (
select UUID, count(*) as 'hits'
from Stats_working
group by UUID
)
AS sub
go
--RESULTS--
UUID hits
-- ---
1.0 1
2.0 2
3.0 3
4.0 4
5.0 5
2 or fewer 3 or more 4 or more
---- ---- ----
3 12 9|||I think a tiny change to Erland's solution might do the trick...
SELECT TotalViews = SUM(cnt), no_of_views
FROM (SELECT cnt, no_of_views = CASE WHEN cnt <= 2 THEN '<= 2 pagewiews'
WHEN cnt = 3 THEN '= 3 pageviews'
ELSE '>= 4 pageviews'
END
FROM (SELECT cnt = COUNT(*)
FROM Stats_Working
GROUP BY UUID) AS a) AS b
GROUP BY no_of_views
So I am cheating a bit. You don't get 3+ pageviews, but 3 exactly.