Related
I am trying to simply extract the list of names of a dataframe columns in Julia, but I get this error message:
ERROR: MethodError: objects of type Array{String,1} are not callable
Use square brackets [] for indexing an Array.
I am simply doing a call names(df).
(It also complains about some IOerror).
Thanks.
Edit: Here is the (ridiculously long) error I get with the MWE suggested below:
julia> df = DataFrame(:a => [2,3,5])
3×1 DataFrame
¦ Row ¦ a ¦
¦ ¦ Int64 ¦
+-----+-------¦
¦ 1 ¦ 2 ¦
¦ 2 ¦ 3 ¦
¦ 3 ¦ 5 ¦
julia> names(df)
ERROR: MethodError: objects of type Array{String,1} are not callable
Use square brackets [] for indexing an Array.
Stacktrace:
[1] top-level scope at REPL[144]:1
caused by [exception 6]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[65]:1
caused by [exception 5]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[65]:1
caused by [exception 4]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[65]:1
caused by [exception 3]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[20]:1
caused by [exception 2]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[20]:1
caused by [exception 1]
IOError: symlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:97 [inlined]
[2] symlink(::String, ::String) at .\file.jl:851
[3] probe_symlink_creation(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\PlatformEngines.jl:131
[4] #unpack#95(::Bool, ::typeof(Pkg.PlatformEngines.unpack), ::String, ::String) at D:\buildbot\wo
rker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:727
[5] #unpack at .\logging.jl:0 [inlined]
[6] #download_verify_unpack#100(::Nothing, ::Bool, ::Bool, ::Bool, ::typeof(Pkg.PlatformEngines.do
wnload_verify_unpack), ::String, ::String, ::String) at D:\buildbot\worker\package_win64\build\usr\
share\julia\stdlib\v1.3\Pkg\src\PlatformEngines.jl:894
[7] #download_verify_unpack at .\none:0 [inlined]
[8] #download_artifact#38(::Bool, ::typeof(Pkg.Artifacts.download_artifact), ::Base.SHA1, ::String
, ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts
.jl:744
[9] #download_artifact at .\none:0 [inlined]
[10] #ensure_artifact_installed#42(::Pkg.BinaryPlatforms.Platform, ::Bool, ::typeof(Pkg.Artifacts.
ensure_artifact_installed), ::String, ::Dict{String,Any}, ::String) at D:\buildbot\worker\package_w
in64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:869
[11] (::Pkg.Artifacts.var"#kw##ensure_artifact_installed")(::NamedTuple{(:platform, :verbose),Tupl
e{Pkg.BinaryPlatforms.Windows,Bool}}, ::typeof(Pkg.Artifacts.ensure_artifact_installed), ::String,
::Dict{String,Any}, ::String) at .\none:0
[12] #ensure_all_artifacts_installed#43(::Pkg.BinaryPlatforms.Platform, ::Nothing, ::Bool, ::Bool,
::typeof(Pkg.Artifacts.ensure_all_artifacts_installed), ::String) at D:\buildbot\worker\package_wi
n64\build\usr\share\julia\stdlib\v1.3\Pkg\src\Artifacts.jl:919
[13] #ensure_all_artifacts_installed at D:\buildbot\worker\package_win64\build\usr\share\julia\std
lib\v1.3\Pkg\src\Operations.jl:0 [inlined]
[14] #download_artifacts#78(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{String,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v
1.3\Pkg\src\Operations.jl:580
[15] #download_artifacts at .\none:0 [inlined]
[16] #download_artifacts#73(::Pkg.BinaryPlatforms.Windows, ::Bool, ::typeof(Pkg.Operations.downloa
d_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share
\julia\stdlib\v1.3\Pkg\src\Operations.jl:570
[17] (::Pkg.Operations.var"#kw##download_artifacts")(::NamedTuple{(:platform,),Tuple{Pkg.BinaryPla
tforms.Windows}}, ::typeof(Pkg.Operations.download_artifacts), ::Array{Pkg.Types.PackageSpec,1}) at
.\none:0
[18] #add#112(::Bool, ::Pkg.BinaryPlatforms.Windows, ::typeof(Pkg.Operations.add), ::Pkg.Types.Con
text, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}) at D:\buildbot\worker\package_win64\b
uild\usr\share\julia\stdlib\v1.3\Pkg\src\Operations.jl:1017
[19] #add at .\none:0 [inlined]
[20] #add#25(::Bool, ::Pkg.BinaryPlatforms.Windows, ::Base.Iterators.Pairs{Union{},Union{},Tuple{}
,NamedTuple{,Tuple{}}}, ::typeof(Pkg.API.add), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1
}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:102
[21] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win6
4\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:72
[22] #add#24 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
69 [inlined]
[23] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:69 [
inlined]
[24] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:
67 [inlined]
[25] add at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API.jl:67 [
inlined]
[26] #add#20(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::typeof(Pkg.AP
I.add), ::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\API
.jl:66
[27] add(::String) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Pkg\src\A
PI.jl:66
[28] top-level scope at REPL[20]:1
You've assigned a variable (of type Vector{String}) called names in your workspace prior to using DataFrames (Julia will prevent you from doing it after). The error message just tells you that you're trying to use names as function, which it isn't in your workspace.
names(df) should work on a data frame:
julia> using DataFrames
julia> df = DataFrame(:a => [2, 3, 5])
3×1 DataFrame
│ Row │ a │
│ │ Int64 │
├─────┼───────┤
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 5 │
julia> names(df)
1-element Array{Symbol,1}:
:a
Can you show us your code and try println(df) as well?
I have a query that will return a grid counting records according to the weekday and the hour, the result of that query is:
And this is the query that builds that table:
DECLARE #p varchar(10)
SET #p =
(
SELECT
[A].[PeriodoAcad]
FROM [dbo].[Periodos_Academicos] [A]
WHERE
([A].[Estado] = 'True')
)
;WITH [pivotData] as
(
SELECT
DATEPART(WEEKDAY,[P].[FechaEnv]) as [Day],
DATEPART(HOUR,[P].[FechaEnv]) as [Hour],
[p].[ID] as [ID]
FROM [dbo].[N_Preinscripcion] [P]
WHERE [P].[Periodo] = #p
)
SELECT
CASE
[Day]
WHEN 1 THEN 'Domingo'
WHEN 2 THEN 'Lunes'
WHEN 3 THEN 'Martes'
WHEN 4 THEN 'Miércoles'
WHEN 5 THEN 'Jueves'
WHEN 6 THEN 'Viernes'
WHEN 7 THEN 'Sábado'
END AS [Dia],
[0] AS [00:00],
[1] AS [01:00],
[2] AS [02:00],
[3] AS [03:00],
[4] AS [04:00],
[5] AS [05:00],
[6] AS [06:00],
[7] AS [07:00],
[8] AS [08:00],
[9] AS [09:00],
[10] AS [10:00],
[11] AS [11:00],
[12] AS [12:00],
[13] AS [13:00],
[14] AS [14:00],
[15] AS [15:00],
[16] AS [16:00],
[17] AS [17:00],
[18] AS [18:00],
[19] AS [19:00],
[20] AS [20:00],
[21] AS [21:00],
[22] AS [22:00],
[23] AS [23:00]
FROM [pivotData]
PIVOT
(
COUNT([ID]) FOR [Hour]
IN
(
[0], [1], [2], [3], [4], [5], [6], [7], [8], [9],[10],[11],[12],[13],[14],[15],[16],[17],[18], [19], [20], [21], [22], [23]
)
) AS [pivoted]
I'm trying to set the cell's colour according to its value. So as you can see, the maximum value on that table is 30, that corresponds to Tuesday 16:00. So i need that 30 is the colour at 100%: the minimum value (that is 0) should be 0%, and the value 1 should be 3.33% ( (1/30) * 100). That will give me the colour scale I need.
How can I detect the maximum value in that table?
So far I've been able to try this solution, but its not working:
DECLARE #p varchar(10)
SET #p =
(
SELECT
[A].[PeriodoAcad]
FROM [dbo].[Periodos_Academicos] [A]
WHERE
([A].[Estado] = 'True')
)
DECLARE #max int
SET #max =
(
;WITH [pivotData] as
(
SELECT
DATEPART(WEEKDAY,[P].[FechaEnv]) as [Day],
DATEPART(HOUR,[P].[FechaEnv]) as [Hour],
[p].[ID] as [ID]
FROM [dbo].[N_Preinscripcion] [P]
WHERE [P].[Periodo] = #p
)
SELECT
CASE
[Day]
WHEN 1 THEN 'Domingo'
WHEN 2 THEN 'Lunes'
WHEN 3 THEN 'Martes'
WHEN 4 THEN 'Miércoles'
WHEN 5 THEN 'Jueves'
WHEN 6 THEN 'Viernes'
WHEN 7 THEN 'Sábado'
END AS [Dia],
[0] AS [00:00],
[1] AS [01:00],
[2] AS [02:00],
[3] AS [03:00],
[4] AS [04:00],
[5] AS [05:00],
[6] AS [06:00],
[7] AS [07:00],
[8] AS [08:00],
[9] AS [09:00],
[10] AS [10:00],
[11] AS [11:00],
[12] AS [12:00],
[13] AS [13:00],
[14] AS [14:00],
[15] AS [15:00],
[16] AS [16:00],
[17] AS [17:00],
[18] AS [18:00],
[19] AS [19:00],
[20] AS [20:00],
[21] AS [21:00],
[22] AS [22:00],
[23] AS [23:00]
FROM [pivotData]
PIVOT
(
COUNT([ID]) FOR [Hour]
IN
(
[0], [1], [2], [3], [4], [5], [6], [7], [8], [9],[10],[11],[12],[13],[14],[15],[16],[17],[18], [19], [20], [21], [22], [23]
)
) AS [pivoted]
)
EDIT:
Regarding the colour: I'm rendering this table on a asp:GridView control, so I intend to bring the background color declared on a div. This will be the desired result on the query (only the result):
DECLARE #p varchar(10)
SET #p =
(
SELECT
[A].[PeriodoAcad]
FROM [dbo].[Periodos_Academicos] [A]
WHERE
([A].[Estado] = 'True')
)
;WITH [pivotData] as
(
SELECT
DATEPART(WEEKDAY,[P].[FechaEnv]) as [Day],
DATEPART(HOUR,[P].[FechaEnv]) as [Hour],
[p].[ID] as [ID]
FROM [dbo].[N_Preinscripcion] [P]
WHERE [P].[Periodo] = #p
)
SELECT
CASE
[Day]
WHEN 1 THEN 'Domingo'
WHEN 2 THEN 'Lunes'
WHEN 3 THEN 'Martes'
WHEN 4 THEN 'Miércoles'
WHEN 5 THEN 'Jueves'
WHEN 6 THEN 'Viernes'
WHEN 7 THEN 'Sábado'
END AS [Dia],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [0]) + '</div>' AS [00:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [1]) + '</div>' AS [01:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [2]) + '</div>' AS [02:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [3]) + '</div>' AS [03:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [4]) + '</div>' AS [04:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [5]) + '</div>' AS [05:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [6]) + '</div>' AS [06:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [7]) + '</div>' AS [07:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [8]) + '</div>' AS [08:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [9]) + '</div>' AS [09:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [10]) + '</div>' AS [10:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [11]) + '</div>' AS [11:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [12]) + '</div>' AS [12:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [13]) + '</div>' AS [13:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [14]) + '</div>' AS [14:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [15]) + '</div>' AS [15:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [16]) + '</div>' AS [16:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [17]) + '</div>' AS [17:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [18]) + '</div>' AS [18:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [19]) + '</div>' AS [19:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [20]) + '</div>' AS [20:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [21]) + '</div>' AS [21:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [22]) + '</div>' AS [22:00],
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [23]) + '</div>' AS [23:00]
FROM [pivotData]
PIVOT
(
COUNT([ID]) FOR [Hour]
IN
(
[0], [1], [2], [3], [4], [5], [6], [7], [8], [9],[10],[11],[12],[13],[14],[15],[16],[17],[18], [19], [20], [21], [22], [23]
)
) AS [pivoted]
So, the line that states:
'<div style="background-color: rgba(120,120,120,1);">' + CONVERT(varchar(max), [23]) + '</div>' AS [23:00]
Should dynamically ser the value of alpha rgba(120,120,120.0.5) according to the calculation of the max size: Result/maxsize
EDIT: I'm guessing you are setting the cell color in some sort of visualization tool like PowerBI or Excel or something. Other users seem to be stuck on this part of your question.
For sanity's sake, I'm going to assume you will put the result of the query that builds your data into either a table or temp table. In my example, I'm using a temp table, #data.
SELECT MAX(maxdata) FROM (
SELECT MAX([00:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([01:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([02:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([03:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([04:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([05:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([06:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([07:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([08:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([09:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([10:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([11:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([12:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([13:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([14:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([15:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([16:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([17:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([18:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([19:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([20:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([21:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([22:00]) AS maxdata FROM #data
UNION ALL
SELECT MAX([23:00]) AS maxdata FROM #data
) md
I have the following query
SELECT [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type], ISNULL([2016], 0) AS '2016', ISNULL([2017],0) AS
'2017'
FROM
(
SELECT CUCODE AS 'Acct', CUNAME AS 'Customer', STKCODE AS 'Code', STKNAME AS 'Description', SUM(OD_QTYORD) AS 'Packs Ordered'
, OD_GROSS AS 'Value', CUSORT AS 'Sale Person', LEFT(CUUSER1,3) AS 'Region', DATEPART(yyyy, OD_DATE) AS 'Year', OH_USER2 AS 'Store Type'
FROM STK_STOCK
INNER JOIN ORD_DETAIL ON STK_STOCK.STKCODE=ORD_DETAIL.OD_STOCK_CODE
INNER JOIN ORD_HEADER ON OD_ORDER_NUMBER=OH_ORDER_NUMBER
INNER JOIN SL_ACCOUNTS ON OH_ACCOUNT=CUCODE
WHERE STKCODE IN ('76958', '27225', '27221', '26962', '26959', '26961', '27226', '26963', '26960')
AND OD_QTYORD > 0
AND CUCODE != 'Z9997'
GROUP BY CUCODE, CUNAME, STKCODE, STKNAME, OD_GROSS, CUSORT, CUUSER1, OD_DATE, OH_USER2
) AS SourceTable
PIVOT
(
SUM([Packs Ordered])
FOR [Year] IN ([2016], [2017])
) AS PivotTable;
The output looks great but I want a subtotal for each 'Acct' and a Grand Total for the whole thing.
Can anyone help with this?
You can use group by grouping sets as below:
SELECT [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type], sum([2016]) as [2016], sum([2017]) as [2017] FROM
(
SELECT [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type], ISNULL([2016], 0) AS '2016', ISNULL([2017],0) AS
'2017'
FROM
(
SELECT CUCODE AS 'Acct', CUNAME AS 'Customer', STKCODE AS 'Code', STKNAME AS 'Description', SUM(OD_QTYORD) AS 'Packs Ordered'
, OD_GROSS AS 'Value', CUSORT AS 'Sale Person', LEFT(CUUSER1,3) AS 'Region', DATEPART(yyyy, OD_DATE) AS 'Year', OH_USER2 AS 'Store Type'
FROM STK_STOCK
INNER JOIN ORD_DETAIL ON STK_STOCK.STKCODE=ORD_DETAIL.OD_STOCK_CODE
INNER JOIN ORD_HEADER ON OD_ORDER_NUMBER=OH_ORDER_NUMBER
INNER JOIN SL_ACCOUNTS ON OH_ACCOUNT=CUCODE
WHERE STKCODE IN ('76958', '27225', '27221', '26962', '26959', '26961', '27226', '26963', '26960')
AND OD_QTYORD > 0
AND CUCODE != 'Z9997'
GROUP BY CUCODE, CUNAME, STKCODE, STKNAME, OD_GROSS, CUSORT, CUUSER1, OD_DATE, OH_USER2
) AS SourceTable
PIVOT
(
SUM([Packs Ordered])
FOR [Year] IN ([2016], [2017])
) AS PivotTable
) a
group by GROUPING SETS ( [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type] )
ORDER BY [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type];
Based on Kannan Kandasamy's reply I got this which worked beautifully:
SELECT (CASE
WHEN GROUPING([Acct])=0 AND
GROUPING([Customer]) = 1 AND
GROUPING([Code]) = 1 AND
GROUPING([Description]) = 1 AND
GROUPING([Sale Person]) = 1 AND
GROUPING([Region]) = 1 AND
GROUPING([Store Type]) = 1
THEN 'Total '+ [Acct]
WHEN GROUPING([Acct])=1 AND
GROUPING([Customer]) = 1 AND
GROUPING([Code]) = 1 AND
GROUPING([Description]) = 1 AND
GROUPING([Sale Person]) = 1 AND
GROUPING([Region]) = 1 AND
GROUPING([Store Type]) = 1
THEN 'Total'
ELSE [Acct]
END) AS Acct , ISNULL([Customer],'') AS 'Customer', ISNULL([Code],'') AS 'Code', ISNULL([Description],'') AS 'Description', SUM(ISNULL([Value],'')) AS 'Value', ISNULL([Sale Person],'') AS 'Sales Person',
ISNULL([Region],'') AS 'Region', ISNULL([Store Type],'') AS 'Store Type', SUM([2016]) AS '2016', SUM([2017]) AS '2017'
FROM
(
SELECT [Acct], [Customer], [Code], [Description], [Value], [Sale Person],
[Region], [Store Type], ISNULL([2016], 0) AS '2016', ISNULL([2017],0) AS
'2017'
FROM
(
SELECT CUCODE AS 'Acct', CUNAME AS 'Customer', STKCODE AS 'Code', STKNAME AS 'Description', SUM(OD_QTYORD) AS 'Packs Ordered'
, OD_GROSS AS 'Value', CUSORT AS 'Sale Person', LEFT(CUUSER1,3) AS 'Region', DATEPART(yyyy, OD_DATE) AS 'Year', OH_USER2 AS 'Store Type'
FROM STK_STOCK
INNER JOIN ORD_DETAIL ON STK_STOCK.STKCODE=ORD_DETAIL.OD_STOCK_CODE
INNER JOIN ORD_HEADER ON OD_ORDER_NUMBER=OH_ORDER_NUMBER
INNER JOIN SL_ACCOUNTS ON OH_ACCOUNT=CUCODE
WHERE STKCODE IN ('76958', '27225', '27221', '26962', '26959', '26961', '27226', '26963', '26960')
AND OD_QTYORD > 0
AND CUCODE != 'Z9997'
GROUP BY CUCODE, CUNAME, STKCODE, STKNAME, OD_GROSS, CUSORT, CUUSER1, OD_DATE, OH_USER2
) AS SourceTable
PIVOT
(
SUM([Packs Ordered])
FOR [Year] IN ([2016], [2017])
) AS PivotTable
) a
group by GROUPING SETS (( [Acct], [Customer], [Code], [Description], [Sale Person],
[Region], [Store Type]),([Acct]),());
I am writing a SQL query for my Access 2010 database. When I attempt to run it, this error appears:
Reserved error (-3304); there is no message for this error.
What is causing this error?
My SQL:
SELECT [Cams TNEP FINAL].[Date Entered]
,[Cam Issues].Department
,[Cam Issues].Equipment
,[Cam Issues].[Operation Issues]
,Sum([Cam Issues].Downtime) AS SumOfDowntime
,IIf([Cam Crew] = '3', 'C-Crew', IIf([Cam Crew] = '2', 'B-Crew', 'A-Crew')) AS Crew
FROM [Cams TNEP FINAL]
INNER JOIN [Cam Issues] ON [Cams TNEP FINAL].[Cam ID] = [Cam Issues].[Cam ID]
GROUP BY [Cams TNEP FINAL].[Date Entered]
,[Cam Issues].Department
,[Cam Issues].Equipment
,[Cam Issues].[Operation Issues]
,IIf([Cam Crew] = '3', 'C-Crew', IIf([Cam Crew] = '2', 'B-Crew', 'A-Crew'))
HAVING (
(
([Cams TNEP FINAL].[Date Entered]) >= #8 / 1 / 2014 #
AND ([Cams TNEP FINAL].[Date Entered]) <= #8 / 1 / 2014 #
)
AND (
([Cam Issues].Department) IN (
'9230-R'
,'9230-F'
)
)
AND ((IIf([Cam Crew] = '3', 'C-Crew', IIf([Cam Crew] = '2', 'B-Crew', 'A-Crew'))) LIKE IIf('ALL' = 'all', '*-Crew', 'ALL'))
)
ORDER BY [Cam Issues].Department
,[Cam Issues].Equipment;
Imagine today it is the 22nd June 2010 (I've used this date as AdvWrks cube is old)
I would like to find the set of days that make up this month i.e. 1st June - 22nd June plus the days in the previous 5 equivalent months to date.
So these days would make up the set:
(1st Jan 2010 - 22nd Jan 2010) +
(1st Feb 2010 - 22nd Feb 2010) +
(1st Mar 2010 - 22nd Mar 2010) +
(1st Apr 2010 - 22nd Apr 2010) +
(1st May 2010 - 22nd May 2010) +
(1st Jun 2010 - 22nd Jun 2010)
The following gives me this set of 132 days:
WITH
SET [Days in Current Month] AS
[Date].[Calendar].[Date].&[20100601]:[Date].[Calendar].[Date].&[20100622]
SET [Mths in Past 6 Mths] AS
Tail
(
[Date].[Calendar].[Month].MEMBERS
,6
)
SET [Prev Equiv MTDs] AS
Generate
(
[Mths in Past 6 Mths]
,Head
(
Descendants
(
[Mths in Past 6 Mths].CurrentMember
,[Date].[Calendar].[Date]
,SELF
)
,[Days in Current Month].Count
)
)
SELECT
{} ON 0
,[Prev Equiv MTDs] ON 1
FROM [Adventure Works];
Is it possible to find this set of days without using the Generate function?
Here is one way:
WITH SET FirstDateOfMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET LastDayOfMonth AS [Date].[Calendar].[Date].&[20100622]
SELECT {} ON 0,
//CurrentMonth
{
FirstDateOfMonth.ITEM(0)
:
LastDayOfMonth.ITEM(0)
}
+
//-1 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
1,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
1,
LastDayOfMonth.ITEM(0)
)
}
+
//-2 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
2,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
2,
LastDayOfMonth.ITEM(0)
)
}
+
//-3 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
3,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
3,
LastDayOfMonth.ITEM(0)
)
}
+
//-4 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
4,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
4,
LastDayOfMonth.ITEM(0)
)
}
+
//-5 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
5,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
5,
LastDayOfMonth.ITEM(0)
)
}
ON 1
FROM [Adventure Works]
And here is one more:
SELECT
{
[Date].[Calendar].[Date].&[20100622].PARENT.FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(1).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(1)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(2).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(2)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(3).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(3)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(4).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(4)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(5).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(5)
)
}
ON 1,
{} ON 0
FROM [Adventure Works]
And one more...
WITH SET FirstDateOfMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET LastDayOfMonth AS [Date].[Calendar].[Date].&[20100622]
MEMBER Measures.PositionOfDate AS {FirstDateOfMonth.ITEM(0):LastDayOfMonth.ITEM(0)}.COUNT
SET Dates AS
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(1).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(2).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(3).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(4).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(5).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
SELECT Dates ON 0,
{} ON 1
FROM [Adventure Works]
And this way too:
WITH SET FirstDateOfSelectedMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET SelectedDate AS [Date].[Calendar].[Date].&[20100622]
MEMBER Measures.PositionOfDate AS {FirstDateOfSelectedMonth.ITEM(0):SelectedDate.ITEM(0)}.COUNT
SELECT
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(5).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(4).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(3).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(2).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(1).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0)
)
ON 1,
{} ON 0
FROM [Adventure Works]
EDIT
Slow code with non-repeating blocks:
WITH SET FirstDateOfSelectedMonth AS [Date].[Calendar].[Date].&[20100601].Parent.FirstChild
SET SelectedDate AS [Date].[Calendar].[Date].&[20100601]
MEMBER Measures.PositionOfDate AS {FirstDateOfSelectedMonth.ITEM(0):SelectedDate.ITEM(0)}.COUNT
MEMBER Measures.PositionOfCurrentDate AS
([Date].[Calendar].currentmember.Parent.FirstChild:[Date].[Calendar].currentmember).COUNT
SELECT
{
[Date].[Calendar].[Date].&[20100601].Parent.LAG(5).FirstChild.ITEM(0)
:
[Date].[Calendar].[Date].&[20100601]
}
HAVING Measures.PositionOfCurrentDate <= Measures.PositionOfDate
ON 1,
{} ON 0
FROM [Adventure Works]